Java Inheritance
In this tutorial, we will learn about Java Inheritance. Inheritance is the fundamental concept of object-oriented programming. Inheritance is the process by which objects of one class acquire the properties of objects of another class. The class that inherits the properties is called a child /sub-class and the class from which the properties are inherited is called the parent /super-class.
Inheritance is a mechanism used to develop new classes by extending the existing classes. The main advantage of inheritance is the reusability of code. Inheritance allows the Java programmer to reuse a class by extending the existing class. The sub-class defines only those features that are unique to it.
extends keyword
The keyword extends is used by the child class to inherit the features of the parent class.
public class <child_class> extends <parent_class> {
...
}
Example:
public class B extends A {
...
}
The existing class is known as the parent class or the superclass. In this example, A is the parent class. The inherited class is known as the subclass or the child class. B is the sub-class.
Inheritance defines an ‘is-a’ relationship between the parent class and the child class. Inheritance is a transitive relationship.
Employee is-a Person
Example:
public class Employee extends Person {
…
}
Java Tutorials
Java Tutorial on this website:
For more information on Java, visit the official website :