Abstraction:
It is the process of hiding the internal implementation details and showing only functionality to the user.
Ways to achieve Abstraction:
- Abstract Class
- Interface
Abstract Class:
- By declaring the "abstract" keyword before the class we can create Abstract Class.
- Example: abstract class TestingColleges{ }
- 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.
- If a class has at least one abstract method then the class must be declared abstract.
- To use an abstract class, we must create a class that extends the abstract class(inheritance) and provide the implementation for all abstract methods.
- 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