Java OCA OCP Practice Question 1138

Question

Which methods compile?

private static int numEdges; 
private int numPoints; 
? 
public static int getNumEdges() { 
   return numEdges; 
} 
? 
public static int getNumPoints() { 
   return numPoints; 
} 

A.  Just  getNumPoints() //from w w w  .  j  a v  a  2 s  . c  om

B.  Just  getNumEdges() 

C.  Both methods 

D.  Neither method 


B.

Note

A static method can access static variables, but not instance variables.

The getNumPoints() method does not compile, so Option B is correct.




PreviousNext

Related