Abstract Class – One-line definition of the abstract class is that it is a class which cannot be instantiated. What does that mean? Remember the example of Vehicle. The superclass Vehicle and subclasses two wheelers, light four wheelers and heavy four wheelers. Vehicle, though has some property; doesn’t mean anything. All it has is a registered owner and a chassis number. You cannot define any object with that information. However, it is essential for the subclass. To ensure that no one uses it even by mistake, Vehicle can be defined as an Abstract Class.
CLASS <class_name> DEFINITION ABSTRACT.
An Abstract Class should have atleast one abstract method which are basically just definition; no implementation. It can have non-Abstract classes as well. Object
An abstract class should have subclasses which can be used for all relevant purposes. They inherit the properties of the Abstract class.
In contrast, Final class marks the culmination of a class so that it cannot be further inherited by any other class. In the above example, assume that a two wheelers can be further defined by brand but in scope of development, it is undesirable because either it adds lots of complexity or creates confusion if an inheriting class overrides the functionality. In that case, two wheelers can be defined as Final which will ensure that no class can inherit two wheelers.
CLASS <class_name> DEFINITION FINAL .
All methods of a Final class are final and cannot be redefined further.
~S
Recent Comments