Search This Blog

Sunday, 21 August 2022

B3. Multilevel Inheritance

//B3. (2019 Syllabus) Multilevel Inheritance
import java.io.*;
class  GrandParent
{
    String gname;
    public void show(String gname)
    {
        System.out.println("Name of the GrandParent is: "+gname);
    }
}

class Parent extends GrandParent
{
    String pname;
    public void show1(String pname)
    {
        System.out.println("Name of the Parent is: "+pname);
    }
}
class Child extends Parent
{
    String cname;
    public void show2(String cname)
    {
        System.out.println("Name of the Child is: "+cname);
    }
}
class  B3
{
    public static void main(String args[])throws IOException
    {
        Child obj=new Child();
        DataInputStream in=new DataInputStream(System.in);
        System.out.println("Enter the name of GrandParent:");
        obj.gname=in.readLine();
        System.out.println("Enter the name of Parent:");
        obj.pname=in.readLine();
        System.out.println("Enter the name of Child:");
        obj.cname=in.readLine();
        obj.show(obj.gname);
        obj.show1(obj.pname);
        obj.show2(obj.cname);
    }
}

No comments :

Post a Comment

FREE Hit Counters