Oracle
1Z0-808 · Question #13
1Z0-808 Question #13: Real Exam Question with Answer & Explanation
The correct answer is C. Hello Java SE 8 Hello p1.MyString@<hashcode>>. See the full explanation below for the reasoning.
Question
Given the definitions of the MyString class and the Test class:
MyString.java:
package p1;
class MyString {
String msg;
MyString(String msg) {
this.msg = msg;
}
}
Test.java:
package p1;
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"));
}
}
What is the result?
Options
- AHello Java SE 8 Hello Java SE 8
- BHello java.lang.StringBuilder@<hashcode1>> Hello p1.MyString@<hashcode2>>
- CHello Java SE 8 Hello p1.MyString@<hashcode>>
- DCompilation fails at the Test class.
Community Discussion
No community discussion yet for this question.