Java OCA OCP Practice Question 321

Question

Given:

class Main{ /*from  w  ww  . j av  a2  s .  co m*/
    public int base; 
    public int height; 
    private static double ANGLE; 

    public static double getAngle (); 
     
    public static void Main (String [] args)  { 
        System .out.println (getAngle ()); 
     } 
} 

Identify the correct statements:

Select 1 option

A. cannot compile because it does not implement setAngle method. 
B. cannot compile because ANGLE cannot be private. 
C. cannot compile because getAngle () has no body. 
D. cannot compile because ANGLE field is not initialized. 
E. cannot compile because of the name of the method Main instead of main. 


C

Note

Option A is wrong, since there is no requirement that a class has to have a setter as well as a getter.

Optional B is wrong, since any field can be made private.

C. and D. are wrong, since it is a static field, it will get a default value of 0.0.

E. is wrong.

A class can have a method named Main.

Since it is not same as main, it will not be considered the standard main method that the JVM can invoke when the program is executed.




PreviousNext

Related