Sunday, July 28, 2013

PROGRAM FOR MULTILEVEL INHERITANCE

a.java:
~~~~~
public class a
{
int x,y;
a(int x1, int y1)
{
x=x1;
y=y1;
}
void displaya()
{
System.out.println("Value of x at class a is "+x);
System.out.println("Value of y at class a is "+y);
}
}

b.java:
~~~~

public class b extends a
{
int m;
b(int x1, int y1, int m1)
{
super(x1,y1);
m=m1;
}
void displayb()
{
System.out.println("Value of m at class b is "+m);
}
}

c.java
~~~~
public class c extends b 
{
int a;
c(int x1, int y1, int m1, int a1)
{
super(x1,y1,m1);
a=a1;
}
void displayc()
{
displaya();
displayb();
System.out.println("Value of a at class c is "+a);
}
}

demomultilevel.java:
~~~~~~~~~~~~~
public class demomultilevel 
{
public static void main(String[] args) 
{
c objc=new c(23,5,4,8);
objc.displayc();
}

}

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips