🎴 Flashcard Mode
Java Constructors and General Programming Quiz
Card1 / 20
Mastered0
Review0
QuestionClick to flip
What is the result of compiling and running the following code? String s=new String("hello"); StringBuffer sb=new StringBuffer("hello"); System.out.println(s.equals(sb));
AnswerClick to flip back
A
Prints "false"
💡 Explanation:
The equals method in the String class checks if the compared object is an instance of String. Since sb is a StringBuffer, the comparison immediately returns false without comparing their character contents.