It is the enhancement of the concept of inheritance. When a subclass is derived from a derived class then this mechanism is known as the multilevel inheritance. The derived class is called the subclass or child class for it's parent class and this parent class works as the child class for it's just above ( parent ) class. Multilevel inheritance can go up to any number of level.
Program that makes use of Multilevel Inheritance in java
/* program To Implement Multilevel Inheritance */
class Fe
{
double fp;
int fr;
Fe(double p1,int r1)
{
fp = p1;
fr = r1;
}
}
class Se extends Fe
{
double sp;int sr;
Se(double p1,int r1,double p2,int r2)
{
super(p1,r1);sp = p2;sr = r2;
}
}
class Te extends Se
{
double tp;int tr;
Te(double p1,int r1,double p2,int r2,double p3,int r3)
{
super(p1,r1,p2,r2);
tp = p3;
tr = r3;
}
double average()
{
return (fp+sp+tp)/3;
}
}
class Student
{
public static void main(String args[])
{
Te student = new Te(78.5,41,71.73,44,79.8,48);
System.out.println("Year\tRoll no.\tPercentage");
System.out.println("FE\t"+student.fr+"\t\t"+student.fp);
System.out.println("SE\t"+student.sr+"\t\t"+student.sp);
System.out.println("TE\t"+student.tr+"\t\t"+student.tp);
System.out.println("\nAverage Performance is " + student.average());
}
}
/* Output *
Year Roll no. Percentage
FE 41 78.5SE 44 71.73
TE 48 79.8Average
Performance is 76.67666666666668 */
Sunday, September 28, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment