Single Choice Not Set

QWhat 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)     
        }
   }

ID: #2249 Inheritance in Java MCQ 10,402 views
Question Info
#2249Q ID
Not SetDifficulty
Inheritance in Java MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 1 2
  • B 2 1
  • C Runtime Error
  • D Compilation Error
Correct Answer

Explanation

Keyword super is used to call constructor of class A by constructor of class B. Constructor of a initializes i & j to 1 & 2 respectively.
output:
$ javac super_use.java
$ java super_use
1 2

Share This Question

Challenge a friend or share with your study group.