Java OCA OCP Practice Question 141

Question

How many of the following methods compile?


public String convert(int value) { 
     ?  return value.toString(); 
} 

public String convert(Integer value) { 
     ?  return value.toString(); 
} 

public String convert(Object value) { 
     ?  return value.toString(); 
} 
  • A. None
  • B. One
  • C. Two
  • D. Three


C.

Note

Objects have instance methods while primitives do not.

Since int is a primitive, you cannot call instance methods on it.

Integer and String are both objects and have instance methods.

Option C is correct.




PreviousNext

Related