Java OCA OCP Practice Question 517

Question

What is the output of the following program?

public class Main {
   String s = "Outer";

   public static void main(String[] args) {
      S2 s2 = new S2();
      s2.display();//from   ww w  .  j a  v a 2 s  . c o  m
   }
}

class S1 {
   String s = "S1";

   void display() {
      System.out.println(s);
   }
}

class S2 extends S1 {
   String s = "S2";

}
  • A. S1
  • B. S2
  • C. null
  • D. S1S2


A

Note

The display() method displays the s variable of the S1 class.




PreviousNext

Related