The correct one is the letter C and it has been tested. The reason for presenting the hashcode is because the MyString object does not have the to String method, whereas the Stringbuilder does, which is why it printed correctly.
Answer is C.
Code -
class MyString {
String msg;
MyString(String msg) {
this.msg=msg;
}
}
// Since both classes are in same package
public class Test {
public static void main(String[] args) {
System.out.println("Hello "+ new StringBuilder("Java SE 8"));
System.out.println("Hello "+ new MyString("Java SE 8"));
}
}
This section is not available anymore. Please use the main Exam Page.1z0-808 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
iSnover
Highly Voted 1 year, 8 months agoDriftKing
Most Recent 10 months agoAnkit1010
1 year, 4 months agoUAK94
1 year, 8 months ago