QuestionQ147

Working with Selected Classes from the Java API

Given the following:

Question Image

What is the output?

  • A true:true
  • B true:false
  • C false:true
  • D false:false
Explanation

The == operator compares object references, and the two Product constructor calls create distinct objects, so ans1 is false. String.equals() compares character content, and both name fields contain "Pen", so ans2 is true.

Community Discussion

No comments yet. Be the first to start the discussion!