Java OCA OCP Practice Question 1460

Question

Which methods compile?

private static int numEdges; 
private int numPoints; 

public int getNumEdges() { 
   return numEdges; 
} 

public int getNumPoints() { 
   return numPoints; 
} 

A.  Just  getNumPoints() //from  w  ww  . j  a v  a2s  .  c  om

B.  Just  getNumEdges() 

C.  Both methods 

D.  Neither method 


C.

Note

An instance method can access both instance variables and static variables.

Both methods compile and Option C is correct.




PreviousNext

Related