Q: What will be the output of the following program code?
public class Test{
public static void main(String args[]){
String s = "what";
StringBuffer sb = new StringBuffer("what");
System.out.print(sb.equals(s)+","+s.equals(sb));
}
}
A.true,true
B.false,true
C. true,false
D.false,false
Correct Option: DExplanation: false,false
Q: How many objects will be created?
String a = new String("Atnylagk");
String b = new String("Atnylagk");
String c = "Atnylagk";
String d = "Atnylagk";
A. 4
B. 3
C. 2
D. None of this
Correct Option: CExplanation: 3
Q: What will be the output?
1. public class Test{
2. public static void main(String args[]){
3. Object myObj = new String[]{"one", "two", "three"};
4. {
5. for(String s : (String[])myObj)
6. System.out.print(s + ".");
7. }
8. }
9. }
A.one.two.three.
B. Compilation fails because of an error at line 3
C.Compilation fails because of an error at line 5
D.An exception is thrown at runtime.
Correct Option: AExplanation: one.two.three.
Q: What will be the output of the following program?
public class Test{
public static void main(String args[]){
String str1 = "one";
String str2 = "two";
System.out.println(str1.concat(str2));
}
}
A. one
B. two
C.onetwo
D.twoone
Correct Option: CExplanation: onetwo
Q:
The String method compareTo() returns
A. true
B.false
C.an int value
D. 1
Correct Option: CExplanation: an int value
Q:
toString() method is defined in
A.java.lang.String
B.java.lang.Object
C. java.lang.util
D. None of these
Correct Option: BExplanation: java.lang.Object
Q: Determine output:
public class Test{
public static void main(String args[]){
String str = null;
if(str.length() == 0){
System.out.print("1");
}
else if(str == null){
System.out.print("2");
}
else{
System.out.print("3");
}
}
}
A.Compilation fails.
B."1" is printed.
C."2" is printed.
D.An exception is thrown at runtime.
Correct Option: DExplanation: An exception is thrown at runtime.
Q: The class string belongs to ................. package.