Q.– Given:-
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") .msg);
}
}
What is the result?
A) Hello Java SE 8
Hello Java SE 8
B) Compilation fails at the Test class.
C) Hello java.lang. StringBuilder@<<hashcode1>>
Hello p1.MyString@<<hashcode2>>
D) Hello Java SE 8
Hello pl.MyString@<<hashcode>>
⧪ please give your answer in a comment section.
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") .msg);
}
}
What is the result?
A) Hello Java SE 8
Hello Java SE 8
B) Compilation fails at the Test class.
C) Hello java.lang. StringBuilder@<<hashcode1>
4 Comments
Option D
ReplyDeleteD
ReplyDeleteHello Java SE 8
ReplyDeleteHelloJava SE 8
HelloJava SE 8
A because System.out.println("Hello" + new MyString ("Java SE 8") .msg);
ReplyDelete