OCA Java SE 8 Method - OCA Mock Question Method 24








Question

Which are true of the following code? (Choose all that apply)

     1:  public class Main { 
     2:    public static void swing() { 
     3:       System.out.print("swing "); 
     4:    } 
     5:    public void climb() { 
     6:       System.out.println("climb "); 
     7:    } 
     8:    public static void play() { 
     9:       swing(); 
     10:      climb(); 
     11:   } 
     12:   public static void main(String[] args) { 
     13:     Main m = new Main(); 
     14:     m.play(); 
     15:     Main m2 = null; 
     16:     m2.play(); 
     17:   } 
     18: } 
  1. The code compiles as is.
  2. There is exactly one compiler error in the code.
  3. There are exactly two compiler errors in the code.




Answer



B

Note

Line 10 does not compile because static methods are not allowed to call instance methods.