What is abstraction: It is the process of showing only necessary details and hiding internal implementation details. If one method is declared as abstract in a class, then whole class is defined as abstract class. Abstraction hides the complex details and shows only essential features.
The abstract keyword is a non-access modifier, used for classes and methods.
Abstract class: It is a restricted class where objects cannot be created. If it needs to be accessed, it must be inherited from another class.
Abstract method : This can be used only in abstract class and it does not have a body. The body is provided by the subclass.
We cannot create an object for an abstract class because it may contain abstract methods without implementation, which makes the class incomplete.
Rules for abstraction:
- Abstract - if a method doesn't have body, the method is abstract method.
- If atleast one method is abstract, then the entire class is abstract class.
- Abstract method don't have body and should not be given body.
Top comments (0)