How to extend classess in Java?
Inheritance is one of object oriented programming concepts. This concept allows classes to inherit commonly used state and behavior from other classes. Inheritance is the way to put commonly used states and behaviours into one class and reuse it.
The class that inherits all the attributes from other class is called as sub class. While, the class that inherited is called as superclass. You can use the extends keyword in class definition to inherit from other classes.
When you apply the final keyword to the class declaration you will make the class final, a final class cannot be extended by other class.
For example below we have, a Truck class and a Sedan that derived from a Car class.
Here the definition of the Car, the Truck and the Sedan classes.