PROGRAM TO IMPLEMENT MULTILEVEL INHERITANCE

//PROGRAM TO IMPLEMENT MULTILEVEL INHERITANCE
class Person
{
String name;
int age;
void getdata(String a,int b)
{
name=a;
age=b;
}
}
class Teacher extends Person
{
String qualification;
float salary;
void getqual(String s)
{
qualification =s;
}
void getsal(float a)
{
salary=a;
}

void display( )
{
System.out.println(“Name of teacher=”+name);
System.out.println(“Age of teacher=”+age);
System.out.println(“Qualification of teacher=”+qualification);
System.out.println(“Salary of teacher=”+salary);
}
}
class guestTeacher extends Teacher
{
float ppl;  //pay per lecture
void getppl(float a)
{
ppl=a;
}
void display( )
{
System.out.println(“Name of teacher=”+name);
System.out.println(“Age of teacher=”+age);
System.out.println(“Qualification of teacher=”+qualification);
System.out.println(“Payment per lecture=”+ppl);
}
}
class testInheritance
{

public static void main(String args[ ])
{
Teacher teach=new Teacher( );
teach.getdata(“Ajay”,50);
teach.getqual(“Msc”);
teach.getsal(1200);
teach.display( );
guestTeacher gteach=new guestTeacher( );
gteach.getdata(“Aman”,30);
gteach.getqual(“Phd”);
gteach.getppl(800);
gteach.display( );
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *


*