Java OCA OCP Practice Question 592

Question

Is it possible to define a class called Thing so that the following method can return true under certain circumstances?

boolean weird(Thing s) { 
     Integer x = new Integer(5); 
     return s.equals(x); 
} 
  • A. Yes
  • B. No


A.

Note

The Thing class is free to override equals() to do anything.

The method can return true when comparing the current instance to an instance of Integer.




PreviousNext

Related