Inheritance

1

What is the output of this program?

  
    class A {
        public int i;
        protected int j;
    }    
    class B extends A {
        int j;
        void display() {
            super.j = 3;
            System.out.println(i + " " + j);
        }
    }    
    class Output {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
A. 1 2
B. 2 1
C. 1 3
D. 3 1

2

What is the output of this program?

    class A {
        public int i;
        public int j;
        A() {
            i = 1;
            j = 2;
	}
    }    
    class B extends A {
        int a;
        B() {
            super();
        } 
    }    
    class super_use {
        public static void main(String args[])
        {
            B obj = new B();
            System.out.println(obj.i + " " + obj.j)     
        }
   }
A. 1 2
B. 2 1
C. Runtime Error
D. Compilation Error

3

What is the output of this program?

  
    class A {
        public int i;
        private int j;
    }    
    class B extends A {
        void display() {
            super.j = super.i + 1;
            System.out.println(super.i + " " + super.j);
        }
    }    
    class inheritance {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
A. 2 2
B. 3 3
C. Runtime Error
D. Compilation Error

4

What is the output of this program?

    class A {
        int i;
    }    
    class B extends A {
        int j;
        void display() {
            super.i = j + 1;
            System.out.println(j + " " + i);
        }
    }    
    class inheritance {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
A. 2 2
B. 3 3
C. 2 3
D. 3 2

5

What is the output of this program?

    class A {
        int i;
        void display() {
            System.out.println(i);
        }
    }    
    class B extends A {
        int j;
        void display() {
            System.out.println(j);
        }
    }    
    class inheritance_demo {
        public static void main(String args[])
        {
            B obj = new B();
            obj.i=1;
            obj.j=2;   
            obj.display();     
        }
   }
A. 0
B. 1
C. 2
D. Compilation Error