Example & Tutorial understanding programming in easy ways.

5. What is Inheritance?

Inheritance is a concept where one class shares the structure and behavior defined in another class. Ifinheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.


Inheritance is the property which allows a Child class to inherit some properties from its parent class. In Java this is achieved by using extends keyword. Only properties with access modifier public and protected can be accessed in child class.



public class A


public String parentName;

public int parentage;

public String familyName;


public class Child extends A{

public String childName;

public int childAge;

public void printMyName()


System.out.println( My name is + childName+ +familyName);




//In above example the child has inherit its family name from the parent class(A) just by inheriting the class.

Read More →
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!