MULTI LEVEL INHERITANCE
MULTI LEVEL INHERITANCE
class Employee
{
String ename;
int age;
void accept(String s,int a)
{
ename=s;
age=a;
}
}
class Manager extends Employee
{
int sal;
void accept_sal(int m)
{ sal=m;
}
}
class Dept extends Manager
{
String deptname;
void accept_dept(String d)
{
deptname=d;
}
void show_all()
{
System.out.print("\nEmployee\n Name: "+ename);
System.out.print("\nAge: "+age);
System.out.print("\nSalary: "+sal);
System.out.print("\nDepartment: "+deptname);
}
public static void main(String ar[])
{
Dept ob=new Dept();
ob.accept("AAA",1);
ob.accept_sal(2000);
ob.accept_dept("XYYYZZZZ");
ob.show_all();
}
}
Comments
Post a Comment