tutorialcup
Inheritance in Java
Inheritance in Java is one of the most important features of an Object-oriented programming system(OOPs). We have seen an overview of inheritance in the previous tutorial of OOPs concepts in Java. In this tutorial, we will understand in detail about inheritance in java and its type with various examples.
What is inheritance in Java
Inheritance in java is a feature that helps to reuse the methods and variables of one class in another class. In other words, it allows a new class to inherit the properties and functions of an existing class without rewriting the code. It implements the parent-child relationship. This means that the child class can directly reuse the variables and functions of the parent class.
Terminologies in Java inheritance
Below are the common terms used with respect to inheritance in java.
Superclass - It is the parent class or base class from which a new class inherits the properties or methods.
Subclass - The class that extends the parent class is a subclass or child class.
extends - a keyword that supports inheritance
super - a keyword that denotes a method, constructor, or variable of a parent class.
Features of Inheritance
- Ability to reuse the existing code of a class
- Supports method overriding
- Allows calling methods of superclass within methods of a subclass using super keyword.
- Does not allow to inherit the final class or override final methods.
- Supports multiple inheritance using interfaces.
Inheritance in Java
Inheritance in Java is one of the most important features of an Object-oriented programming system(OOPs). We have seen an overview of inheritance in the previous tutorial of OOPs concepts in Java. In this tutorial, we will understand in detail about inheritance in java and its type with various examples.
What is inheritance in Java
Inheritance in java is a feature that helps to reuse the methods and variables of one class in another class. In other words, it allows a new class to inherit the properties and functions of an existing class without rewriting the code. It implements the parent-child relationship. This means that the child class can directly reuse the variables and functions of the parent class.
Terminologies in Java inheritance
Below are the common terms used with respect to inheritance in java.
Superclass - It is the parent class or base class from which a new class inherits the properties or methods.
Subclass - The class that extends the parent class is a subclass or child class.
extends - a keyword that supports inheritance
super - a keyword that denotes a method, constructor, or variable of a parent class.
Features of Inheritance
- Ability to reuse the existing code of a class
- Supports method overriding
- Allows calling methods of superclass within methods of a subclass using super keyword.
- Does not allow to inherit the final class or override final methods.
- Supports multiple inheritance using interfaces.