Q.1

What will be the output of the program?

int i = (int) Math.random();
  • i = 0
  • i = 1
  • value of i is undetermined
  • Statement causes a compile error
Q.2

Which of the following would compile without error?

  • int a = Math.abs(-5);
  • int b = Math.abs(5.0);
  • int c = Math.abs(5.5F);
  • int d = Math.abs(5L);
Q.3

Which of the following are valid calls to Math.max?

  1. Math.max(1,4)
  2. Math.max(2.5)
  3. Math.max(7)
  4. Math.max(-1.-2.8f)
  • 1, 2 and 4
  • 2, 3 and 4
  • 1, 2 and 3
  • 3 and 4
Q.4

What will be the output of the program?

String d = "bookkeeper";
d.substring(1,7);
d = "w" + d;
d.append("woo");  /* Line 4 */
System.out.println(d);
  • wookkeewoo
  • wbookkeeper
  • wbookkeewoo
  • Compilation fails.
Q.5

What will be the output of the program?

public class BoolTest 
{
    public static void main(String [] args) 
    {
        int result =
        Boolean b1 = new Boolean("TRUE");
        Boolean b2 = new Boolean("true");
        Boolean b3 = new Boolean("tRuE");
        Boolean b4 = new Boolean("false");

        if (b1 == b /* Line*/
            result =        if (b1.equals(b) /* Line*/
            result = result +        if (b2 == b /* Line*/
            result = result +        if (b2.equals(b) /* Line*/
            result = result +        if (b2.equals(b) /* Line*/
            result = result +
        System.out.println("result = " + result);
    }
}
  • 0
  • 1
  • 10
  • 10010
Q.6

Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?

  • (int)Math.min(d);
  • (int)Math.max(d);
  • (int)Math.abs(d);
  • (int)Math.floor(d);
Q.7

What will be the output of the program?

String a = "newspaper";
a = a.substring(5,7);
char b = a.charAt(1);
a = a + b;
System.out.println(a);
  • apa
  • app
  • apea
  • apep
Q.8

What will be the output of the program?

public class StringRef 
{
    public static void main(String [] args) 
    {
        String s1 = "abc";
        String s2 = "def";
        String s3 = s  /* Line 7 */
        s2 = "ghi";
        System.out.println(s1 + s2 + s3);
    }
}
  • abcdefghi
  • abcdefdef
  • abcghidef
  • abcghighi
Q.9

What will be the output of the program?

class A 
{ 
    public A(int x){} 
} 
class B extends A { } 
public class test 
{ 
    public static void main (String args []) 
    {
        A a = new B(); 
        System.out.println("complete"); 
    } 
}
  • It compiles and runs printing nothing
  • Compiles but fails at runtime
  • Compile Error
  • Prints "complete"
Q.10

What will be the output of the program?


String a = "ABCD"; 
String b = a.toLowerCase(); 
b.replace('a','d'); 
b.replace('b','c'); 
System.out.println(b);
  • abcd
  • ABCD
  • dccd
  • dcba
Q.11

What will be the output of the program?

public class ObjComp 
{
    public static void main(String [] args ) 
    {
        int result =        ObjComp oc = new ObjComp();
        Object o = oc;

        if (o == oc)  
            result =        if (o != oc)  
            result = result +        if (o.equals(oc) )  
            result = result +        if (oc.equals(o) )  
            result = result +
        System.out.println("result = " + result);
    }
}
  • 1
  • 10
  • 101
  • 1101
Q.12

What two statements are true about the result obtained from calling Math.random()?

  1. The result is less than 0.0.
  2. The result is greater than or equal to 0.0..
  3. The result is less than 1.0.
  4. The result is greater than 1.0.
  5. The result is greater than or equal to 1.0.
  • 1 and 2
  • 2 and 3
  • 3 and 4
  • 4 and 5
Q.13

What will be the output of the program?

String s = "ABC"; 
s.toLowerCase(); 
s += "def"; 
System.out.println(s);
  • ABC
  • abc
  • ABCdef
  • Compile Error
Q.14

What will be the output of the program?

int i =j =
do 
{
    if(i++ > --j) /* Line 4 */
    {
        continue; 
    } 
} while (i < 5); 
System.out.println("i = " + i + "and j = " + j); /* Line 9 */
  • i = 6 and j = 5
  • i = 5 and j = 5
  • i = 6 and j = 6
  • i = 5 and j = 6
Q.15

What will be the output of the program?

public class ExamQuestion{
    static int x; 
    boolean catch()
    {
        x++; 
        return true; 
    } 
    public static void main(String[] args)
    {
        x=
        if ((catch() | catch()) || catch()) 
            x++; 
        System.out.println(x); 
    } 
}
  • 1
  • 2
  • 3
  • Compilation Fails
Q.16

What will be the output of the program?

public class Example 
{
    public static void main(String [] args) 
    {
        double values[] = {-2.-1.0.4};
        int cnt =        for (int x=x < values.length; x++) 
        {
            if (Math.round(values[x] + .== Math.ceil(values[x])) 
            {
                ++cnt;
            }
        }
        System.out.println("same results " + cnt + " time(s)");
    }
}
  • same results 0 time(s)
  • same results 2 time(s)
  • same results 4 time(s)
  • Compilation fails.
0 h : 0 m : 1 s