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));
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
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option C
Explanation
StringBuffer MCQ Question
StringBuffer x = new StringBuffer("Hello");
StringBuffer y = new StringBuffer("HELLO");
System.out.println(x.equalsIgnoreCase(y));
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(...)
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic