Create two class A and B. Class B inherits class A. use the instance variable of class A through object of class B.


class A
{
    int i=10,n=12;
   
}
class B extends A
{
    int a=111,b=222;   
}
class Inheritance
{
    public static void main(String args[])
    {
        B obj=new B();
        System.out.println("class A value is "+obj.i);
        System.out.println("class A value is "+obj.n);
        System.out.println("class B value is "+obj.a);
        System.out.println("class B value is "+obj.b);
    }
}

0 comments:

Post a Comment

Digital Marketing

Subscribe to RSS Feed Follow me on Twitter!