29/01/25 ----------- Q)What are the types of inheritance? 1)Single Inheritance 2)Multiple Inheritance =>Single inheritance is that form of inheritance in which,a child class inherits only one parent class. =>There are 2 spcial cases of single inheritance. 1)Hierarchical 2)Multi level =>Multiple inheritance is that form of inheritance in which, a child class inherits from more than on parent class. Note:- Java doesn't support Multiple inheritance. DIAGRAM =>Hierarchical inheritance is a special case of single inheritance in which, a parent class has multiple sub classes. =>Multi-level inheritance is that form single inheritance in which, a sub class acts as a parent class for another sub class. Q)Write a Java program that implements hierarchical inheritance. class Person{ int age; String name; void storePersonData(int age,String name){ this.age=age; this.name=name; } void displayPersonData(){ System.out.println("NAME:"+name); System.out.println("AGE:"+age); } } class Employee extends Person{ int empno; float salary; void storeEmployeeData(int eno,float sal, int age,String name) { storePersonData(age,name);//inherited method empno=eno; salary=sal; } void displayEmployeeData(){ displayPersonData(); System.out.println("EMPNO:"+empno); System.out.println("SALARY Rs."+salary); } } class Student extends Person{ int rollno; int marks; void storeStudentData(int rollno,int marks,int age,String name){ storePersonData(age,name); this.rollno=rollno; this.marks=marks; } void displayStudentData(){ displayPersonData(); System.out.println("ROLLNO:"+rollno); System.out.println("MARKS:"+marks); } } class HierarchicalInheritanceApplication{ public static void main(String[] args) { Employee e=new Employee(); e.storeEmployeeData(10001,50000,28,"Rama"); e.displayEmployeeData(); } }