Java OCA OCP Practice Question 907

Question

What is the output of the following program?

public class Main {
   public static void main(String[] args) {
      new S2();/*from   www  . j a v  a2  s.  c  o  m*/
   }

   Main() {
      System.out.print("S1");
   }
}

class S2 extends Main {
   S2() {
      System.out.print("S2");
   }
}
  • A. S1
  • B. S2
  • C. S1S2
  • D. S2S1


C

Note

The superclass (S1) constructor is invoked before the subclass (S2) constructor.




PreviousNext

Related