Inheritance in java

Inheritance is the process of object of one class having the properties of objects of another class. The class which shows the properties of another class is called the child class or the sub class and the class from which the child class inherits is called the parent class or super class. Inheritance is one of the most important object oriented concept in java. By using inheritance we can combine functionalities of many classes together. By following inheritance it is easy to add more functionality to an existing java application.  For further clarification consider the following example.

In the figure given above, you can see that the birds are classified into two categories  one is flying and another is non-flying. The flying and non flying birds have their on different behaviors but yet they are came under the common family birds. From this example you can see that the flying birds and non flying birds are inherits some common behaviors from the birds category. So we can say that the birds category is the parent of the sub categories flying and non flying. This process is called the process of inheritance. In java also we follows the same scenario. 

Consider the following java class hierarchy.
In the figure CLASS_A and CLASS_B are the child of the class PARENT_CLASS. This parent child relationship is expressed programatically as follows. 

class PARENT_CLASS
{

}

class CLASS_A extends PARENT_CLASS
{

}

class CLASS_B extends PARENT_CLASS
{

}

The keyword extends is used for establishing inheritance in java. 
Example:

class ParentClass
{
public String parentMethod()
{
return "Hello from parent method";
}
}

class ChildClass extends ParentClass
{
public String childMethod()
{
return "Hello from child method";
}
}
class InheritanceDemo
{
public static void main(String args[])
{
ChildClass child = new ChildClass();
System.out.println(child.parentMethod());
System.out.println(child.childMethod());
}
}

Output:
From the example you can see that it is possible to access the parent class methods by using the child class objects. In this example we create an object of the child class. By using this object (child) we  can also access the parent class method parentMethod. 
                   ChildClass child = new ChildClass();
                   System.out.println(child.parentMethod());
So we can say that instances of the parent class and child class are same. You can test this by using the following statements.
System.out.println(child instanceof ParentClass );
System.out.println(child instanceof ChildClass );
By adding the above code segments to the above program, you got the following output.

Output:

Note:
The java programming language dose't support the multiple inheritance.