/* **********INHERITANCE *********************/
class GrandFather
{
int c;
void gfathermethod()
{
System.out.println("I am a method of GrandFather");
}
}
class Father extends GrandFather
{
int a;
void fathermethod()
{
System.out.println("I am a method of Father");
}
}
class Son extends Father
{
int b;
void sonmethod()
{
System.out.println("I am a method of Son");
}
}
class simpleinheritance
{
public static void main(String args[])
{
GrandFather grand=new GrandFather();
grand.c=100;
grand.gfathermethod();
Father father = new Father();
Son son = new Son();
father.a=10;
father.c=200;
father.fathermethod();
System.out.println("father.a = " + father.a);
System.out.println("father.a = " + father.c);
son.a=20;
son.b =30;
son.c=300;
System.out.println("son.a = " + son.a + " son.b = " + son.b+"son.c = " +son.c);
son.fathermethod();
son.sonmethod();
son.gfathermethod();
}
}
No comments:
Post a Comment