String in Java

Answer all questions carefully. After submission, you will see a detailed result and answer review.

Question 1
The class string belongs to ................. package.
Question 2
What will be the output of the following program code? <pre class="prettyprint"> 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)); } } </pre>
Question 3
What will be the output of the following program? <pre class="prettyprint"> public class Test{ public static void main(String args[]){ String s1 = "java"; String s2 = "java"; System.out.println(s1.equals(s2)); System.out.println(s1 == s2); } } </pre>
Question 4
How many objects will be created? <pre class="prettyprint"> String a = new String("Atnylagk"); String b = new String("Atnylagk"); String c = "Atnylagk"; String d = "Atnylagk"; </pre>
Question 5
Determine output: <pre class="prettyprint"> 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"); } } } </pre>
Question 6
What will be the output? <pre class="prettyprint"> public class Test{ public static void main (String[] args){ String test = "a1b2c3"; String[] tokens = test.split("\\d"); for(String s: tokens) System.out.print(s); } } </pre>
Question 7
What will be the output? <pre class="prettyprint"> String str1 = "abcde"; System.out.println(str1.substring(1, 3)); </pre>
Question 8
The String method compareTo() returns
Question 9
What will be the output? <pre class="prettyprint"> 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. } </pre>
Question 10
What will be output? <pre class="prettyprint"> String S1 = "S1 ="+ "123"+"456"; String S2 = "S2 ="+(123+456); </pre>