In this Java tutorial, you will learn what inheritance is when it comes to Object Oriented Programming, and how Inheritance is implemented in Java with classes, with examples.


Inheritance is an Object Oriented Concept in Java. It allows an object of a class to own the variables and methods of another class. In Java, Inheritance is realized using the keyword extends.

In a parent-child analogy, child inherits parents variables(money, house, etc.,) and methods(behaviors from genetics). The same way, an object of a child class, which extends a Parent class, can access the variables and methods of Parent class as of its own.

Inheritance in Java - Tutorialkart
Block diagram – Inheritance in Java

More about inheritance

The following are the most important list of points to remember about the Java Inheritance concept.

  • Inheritance is an Object Oriented Programming(OOP) concept.
  • A Child class can inherit only one Parent class. (A child can have only one parent)
  • Multiple (sub) classes can inherit a same (super) class. (A parent can have multiple children)
  • Child class may use the methods and variables of the Parent class.
  • A child class can inherit all methods of parent class except those which are priavte.

When a Child class inherits a Parent class, compiler does not copy the methods of Parent class to Child class. But, the compiler makes a reference to the methods in the instance of Parent class.


Example Program

Usually in Java, Parent class is also called as Super class, and Child class is also called as Sub Class.

In this example project, we shall create a Super Class, and a Sub Class

Following is the parent class or super class.


 * @author tutorialkart
public class MobilePhone {
	public int price;
	public void makeCall(){
	public void getCharge(){
	// private method is not visible to other classes
	private void check(){
		System.out.println("This is private to MobilePhone");

Following is the child class or subclass.


/** This class inherits MobilePhone
 * @author tutorialkart
public class SmartPhone extends MobilePhone {
	public String name;
	public static void main(String[] args) {
		SmartPhone sonyXZ = new SmartPhone();
		// variable of SmartPhone (Sub Class) = "Sony XZ";
		// variable of MobilePhone (Super Class)
		sonyXZ.price = 40500;
		// method of SmartPhone (SubClass)
		// methods of MobilePhone (Super Class)
	public void playVideo(){
		System.out.println("Playing video..");

Run program, and the output to console should be as shown in the following.


Playing video..


In this Java Tutorial, we learned what Inheritance mean in Java and how to realize it using extends keyword.