Witscale Test Center

Sample test


Sample test

1.            Which of the following expressions are valid?

 

A.    int a = 0x1f; a = 4 ^ a;

B.    int a = 0; a = ~ a;

C.    int a = 5; a += -1;

D.    int a = 1; if(!a) {}

E.    int a = 6; int b = a ? 1 : 0;

 

 

2.    Which of the following prints the value 8?

 

A.    System.out.println(32 % 4);

B.    System.out.println(32 <<< 36);

C.    System.out.println(32 >>> 4);

D.    System.out.println(64 >>> 8);

E.    System.out.println(64 >> 3);

F.    System.out.println(2 << 2 << 2);

 

 

3.    Consider the following variable declarations.

 

String a = "Hello World";

int b = 9 ;

float f = 2.76f;

 

Which of the following are legal expressions?

 

G.    b += a

H.    a *= b

I.    f + a

J.    a += f

K.    a += a

L.    f – b

 

 

4.    Consider the following variable declarations.

 

String a = new String(“1010”);

String b = “1010”;

int c = 1010;

int d = 0x1010;

Integer e = new Integer(1010);

Integer f = new Integer(1010);

 

Which of the following will print message “Equal” after execution?

 

A.    if (c == d) {

System.out.println("Equal");

   }

B.    if (a == b) {

System.out.println("Equal");

   }

 

C.    if (e == f) {

System.out.println("Equal");

   }

D.    if (a.equals(b)) {

System.out.println("Equal");

   }

E.    if (d == e) {

       System.out.println("Equal");

   }

F.    if (a == c) {

System.out.println("Equal");

   }

 

5.    What will happen when the following code is executed?

 

                                        1.      public class Tester {

                                        2.        public static void main(String[] args) {

                                        3.          int a = 6, b = 7;

                                        4.          if (a++ == b)

                                        5.             System.out.println(a == b ? --b : b++);

                                        6.          else

                                        7.             System.out.println("b = " + b);

                                        8.        }

                                        9.      }

 

A.      6

B.      8

C.      true

D.     b = 7

E.      Nothing. The code will fail to compile at line 5 as it passes an expression to println method.

F.       b = 8

 

 

6.    Consider the following code.

 

                                        1.            import java.util.Vector;

                                        2.            public class Tester {

                                        3.              static Vector v;

                                        4.              static String s;

                                        5.              public static void main(String[] args) {

                                        6.               v = new Vector();

                                        7.                if (v instanceof Object && s == null)

                                        8.                 s = "checked";

                                        9.               else

                                    10.                 s = "unchecked";

                                    11.               System.out.println(s);

                                    12.              }

                                    13.            }

 

 

What will be printed when the following code is executed?

 

A.    null

B.    checked

C.    unchecked

D.     “”

E.      Nothing, this code will fail to compile at line 7

F.       This code will compile but fails at runtime, as v is not an instance of Object class.

 

 

7.    What will be the value of a & b after the following code snippet is executed?

 

byte a = 15;         //Bit representation 00001111

byte b = 1;          //Bit representation 00000001

 

A.      00001111

B.      00001110

C.      1

D.     0

E.      15

 

 

8.    What will be the output of the following code fragment?

 

                                        4.            String s1 = new String("The obstacle is the path");

                                        5.      String s2 = new String("The obstacle is the path");

                                        6.      String s3 = "The obstacle is the path";

                                        7.      String s4 = s3;

                                        8.      String s5 = s2;

                                        9.      if(s1==s2)

                                    10.        System.out.print("Identical ");

                                    11.      if(s1.equals(s3))

                                    12.        System.out.print("Equal ");

                                    13.      if(s2.equals(s3))

                                    14.        System.out.print("Equal ");

                                    15.      if(s4 == s5)

                                    16.        System.out.print("Identical ");

                                    17.      if(s4.equals("The obstacle is the path"))

                                        18.        System.out.print("Equal "); 

 

 

A.    Equal Equal Equal

B.    Equal Equal Identical  Equal

C.    Identical Identical Equal

D.    Equal Equal

E.    Equal Identical

F.    Identical Equal Equal Identical Equal

 

 

9.  Consider the following code.

 

                                        1.               public class Tester {

                                        2.          public static void main(String[] args) {

                                        3.            String[] names = { "Mickey", "Pluto", "Donald" };

                                        4.            int a = 4;

                                        5.            float b = 7.0f;

                                        6.            for (int i = 0; i < names.length; i++) {

                                        7.             if (names[i + 1].equals("Pluto") & a++ < b) {

                                        8.               names[i] = "Hello " + names[i];

                                        9.               break;

                                    10.           }

                                    11.          }

                                    12.          for (int i = 0; i < names.length; i++) {

                                    13.            System.out.println(names[i]);

                                    14.          }

                                    15.       

                                    16.        }

                                    17.      }

 

Which of the following is part of output when the give code?

 

A.    Hello Pluto

B.    Hello Donald

C.    Hello Mickey

D.    Mickey

E.    Pluto

F.    Donald

G.    null

H.     This program will throw ArrayIndexOutOfBoundsException at runtime.

 

 

10.  Consider the following code.

           

boolean condition1 = false;

boolean condition2 = true;

boolean condition3 = condition1 ^ condition2;

 

Which of the following expressions return true?

 

A.      condition1 & condition2 | condition2 & condition3

B.      ~condition1

C.      condition1 | condition2 & condition2 | condition3

D.     condition2 = !condition1

E.      condition2 != condition1

F.       condition1 ^ condition3