Java Programming
About Lesson

If more than one child classes are derived from single parent class then it is known as hierarchical inheritance.

//example showing hierarichal inheritance
class person
{
String name;
}

class student extends person
{
String course;
}

class employee extends person
{
String desg;
}

public class HeirarichalInheritanceEg {

public static void main(String[] args) {
student obj1=new student();
employee obj2=new employee();

obj1.name=”Raju”;
obj1.course=”MCA”;

obj2.name=”Rani”;
obj2.desg=”Manager”;

System.out.println(“Displaying data from student class object: “);
System.out.println(“Name: “+obj1.name);
System.out.println(“Name: “+obj1.course);

System.out.println(“\nDisplaying data from employee class object: “);
System.out.println(“Name: “+obj2.name);
System.out.println(“Designation: “+obj2.desg);

}

}

You cannot copy content of this page