What will be the output of the following Java 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

1 thought on “What will be the output of the following Java program?”

  1. a
    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

Leave a Comment