1. What is the output of the following
   StringBuffer sb1 = new StringBuffer("Amit");
   StringBuffer sb2= new StringBuffer("Amit");
   String ss1 = "Amit";
   System.out.println(sb1==sb2);
   System.out.println(sb1.equals(sb2));
   System.out.println(sb1.equals(ss1));
   System.out.println("Poddar".substring(3));

Ans:
a) false
   false
   false
   dar
b) false
   true
   false
   Poddar
c) Compiler Error
d) true
   true
   false
   dar

 

2.What is the output of following if the return value is "the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument"  (Assuming  written inside main)

String s5 = "AMIT";
String s6 = "amit";
System.out.println(s5.compareTo(s6));
System.out.println(s6.compareTo(s5));
System.out.println(s6.compareTo(s6));

Ans
a> -32
    32
    0
b>  32
    32
    0
c>  32
   -32
    0
d>  0
    0
    0

 

3.What is the output  (Assuming  written inside main)
    String s1 = new String("amit");
    String s2 = s1.replace('m','i');
    s1.concat("Poddar");
    System.out.println(s1);
    System.out.println((s1+s2).charAt(5));

a) Compile error
b) amitPoddar
   o
c) amitPoddar
   i
d) amit
   i

 

4.What is the output  (Assuming  written inside main)
    String s1 = new String("amit");
    System.out.println(s1.replace('m','r'));
    System.out.println(s1);
    String s3="arit";
    String s4="arit";
    String s2 = s1.replace('m','r');
    System.out.println(s2==s3);
    System.out.println(s3==s4);

a)  arit
    amit
    false
    true
b)  arit
    arit
    false
    true
c)  amit
    amit
    false
    true
d)  arit
    amit
    true
    true

5.Which one does not extend java.lang.Number
    1)Integer
    2)Boolean
    3)Character
    4)Long
    5)Short

 

6.Which one does not have a valueOf(String) method
    1)Integer
    2)Boolean
    3)Character
    4)Long
    5)Short

7.What will be the output of line 5
    1 Choice c1 = new Choice();
    2 c1.add("First");
    3 c1.addItem("Second");
    4 c1.add("Third");
    5 System.out.println(c1.getItemCount());
a)    1
b)    2
c)    3
d)    None of the above

 

8.What will be the output of follwing
{
double d1 = -0.5d;
System.out.println("Ceil for d1 " + Math.ceil(d1));
System.out.println("Floor for d1 " +Math.floor(d1));
}

Answers:
a)  Ceil for d1 0
    Floor for d1 -1;
b)  Ceil for d1 0
    Floor for d1 -1.0;
c)  Ceil for d1 0.0
    Floor for d1 -1.0;
d)  Ceil for d1 -0.0
    Floor for d1 -1.0;

 

9.Which of the following wrapper classes can not
take a "String" in constructor

1) Boolean
2) Integer
3) Long
4) Character
5) Byte
6) Short

 

10.What is the output of following
    Double d2 = new Double("-5.5");
    Double d3 = new Double("-5.5");
    System.out.println(d2==d3);
    System.out.println(d2.equals(d3));

a)  true
    true
b)  false
    false
c)  true
    false
d)  false
    true