The Inheritance in Java basics is
- The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called inheritance. The aim of inheritance is to provide the reusability of code so that a class has to write only the unique features and rest of the common properties and functionalities can be extended from the another class.
- Inheritance is a process of defining a new class based on an existing class by extending its common data members and methods.
- Inheritance allows us to reuse of code, it improves reusability in your java application.
- The biggest advantage of Inheritance is that the code that is already present in base class need not be rewritten in the child class.
Inheritance is used in java :
- For Method Overriding (so runtime polymorphism can be achieved).
- For Code Reusability.
Terms used in Inheritance
- Class:
- A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
- Sub Class/Child Class:
- Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
- Super Class/Parent Class:
- Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.
- Reusability:
- As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.