QuestionQ163

Using Operators and Decision Constructs

Given the following code fragment:

Question Image

Which code fragment, when inserted at line n1, causes the App class to print Equal?

Question Image

  • A Option A
  • B Option B
  • C Option C
  • D Option D
Explanation

String.equals compares string contents. Converting "Java" to lowercase produces "java", which has the same character sequence as str2, so the condition is true. == tests reference identity rather than string content, and invoking toLowerCase() without assigning or using its returned value does not alter the original immutable string.

Learn more

Community Discussion

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