Abstract classes
I have been learning the most important concepts of java which is the object oriented programming and today I learnt about the abstract classes and method and wanted to share my thoughts on them.
Abstract class: If a class contains an abstract method, then it is termed as an abstract class and it should also be declared with the abstract keyword.
The fun part:
Abstract classes are like a template or a thought. It has abstract methods but no definition. When a child class extends (inherits) this abstract class, the abstract class allows the child class to over ride it in its own way.
For example, if an abstract class has an abstract method known as greet(), then the child class can override it in its own way like greet() can now say good mrng or good afternoon.
Note:
1. Objects of abstract class cannot be instantiated.
2. The child class should either override the abstract method of the abstract parent class or declare itself as an abstract class.
3. Refrence of the abstract class can be created but only if we override the abstract method inside it.
4. Unless and until the abstract method is not given a definition via overriding by the subclass, we cannot implement the subclass/ create an object of it.
Real world analogy:
Parent class - phone model
Abstract method - switch on()
Child class - samsung
Overridden method- while the phone switches off, implement this graphic or produce this sound.