MCQ Single Best Answer Moderate

Q[StringBuffer]
The code snippet given below will result in:
StringBuffer x = new StringBuffer("Hello");
StringBuffer y = new StringBuffer("HELLO");
System.out.println(x.equalsIgnoreCase(y));

ID: #24936 Competency focused Practice Questions ISC Class XII Computer Science 5 views
Question Info
#24936Q ID
ModerateDifficulty
Competency focused Practice Questions ISC Class XII Computer ScienceTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A boolean value false
  • B boolean value true
  • C undeclared method equalsIgnoreCase(...)
  • D String literals mismatch
Correct Answer: Option C

Explanation

StringBuffer MCQ Question

StringBuffer x = new StringBuffer("Hello");
StringBuffer y = new StringBuffer("HELLO");
System.out.println(x.equalsIgnoreCase(y));

Correct Answer: (c) undeclared method equalsIgnoreCase(...)

Explanation:

In Java, the class StringBuffer does NOT have a method called equalsIgnoreCase().

The method equalsIgnoreCase() belongs to the String class, not StringBuffer. Therefore, calling this method on a StringBuffer object will cause a compile-time error.

Java checks method availability at compile time. Since x and y are StringBuffer objects, the compiler cannot find equalsIgnoreCase(), resulting in an error.

So the program does not run at all, and the correct answer is:
undeclared method equalsIgnoreCase(...)

Share This Question

Challenge a friend or share with your study group.