Your ultimate guide

Java & C#_Object Oriented Programing5

Abstraction:
    It is the process of hiding the internal implementation details and showing only functionality to the user.
Ways to achieve Abstraction:
  1. Abstract Class
  2. Interface
Abstract Class:
  1. By declaring the "abstract" keyword before the class we can create Abstract Class.
    • Example: abstract class TestingColleges{    }
  2. Abstract Class can have abstract methods and non-abstract methods(method with the body).
    • Abstract Method: A method that is declared in an abstract class, but doesn't have an implementation is called an abstract method. We can declare an abstract method using the abstract keyword.
    • Non-abstract method: A method that has complete implementation.
  3. If a class has at least one abstract method then the class must be declared abstract.
  4. To use an abstract class, we must create a class that extends the abstract class(inheritance) and provide the implementation for all abstract methods.
  5. Java doesn't support multiple inheritance so we are only allowed to extend one class(abstract or not). There is where interfaces become useful.

No comments:

Post a Comment