What is 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.

In the below example the Address has inherit its id from the Employee class just by inheriting the class.

				
					public class Employee {

	public String employeeName;
	public int id;
}

public class Address extends Employee {
	public String city;
	public int state;

	public void printDetails() {
		System.out.println("My details is " + city + " " + id);
	}
}