Witscale Test Center

Sample Test


Sample Test

1.    Which of the following are keywords/reserved words in Java?

 

A.    Arrays

B.    method

C.    class

D.    length

E.    Interface

F.    implements

 

 

2.    Which of the following are valid declarations of variables?

 

A.    String message = “A”;

B.    int  a = 60.80;

C.    char a = ‘\u4ace’;

D.    long bigNumber = 1L;

E.    boolean True = true;

 

 

3.    Which of the following are invalid method declarations?

 

A.    void test(int int1, int int2) {}

B.    void Class() {}

C.    void switch(int number1, int number2) {}

D.    void _$_(String extend) {}

E.    boolean assert_this() { return true; }

 

 

4.    What is the range of values a variable of byte type can hold?

 

A.      –(28) to (28) - 1

B.      –128 to 127

C.      –127 to 128

D.     –(27) to (27)

E.      (–(27) – 1) to (27)

F.       0 to 255

G.     It is platform dependent.

 

 

5.    Which of the following is the correct way of getting the size of array primeNumbers?

 

A.    primeNumbers.length()

B.    primeNumbers.length

C.    primeNumbers.length - 1

D.    primeNumbers.size

E.    primeNumbers.getSize() - 1

 

 

6.    Which of the following array declarations are valid? (Choose all the correct answers)

 

A.    int matrix[][] = new int[4][];

B.    int[] matrix[] = new int[4][];

C.    int[] matrix = new int[5][];

D.    int[][] matrix = new int[4][5];

E.    int[] matrix = new int[][5];

 

 

7.    What will be the result of compiling and executing the following program?

 

                                                        1.            package com.example.scjp.sampletests;

                                                        2.               public class ArrayTester {

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

                                                        4.                   int numbers[];

                                                        5.                   System.out.println(numbers[0]);

                                                        6.                }

                                                        7.               }

 

A.      The program will not compile because numbers[0] is being read before being initialized.

B.      The program will throw a runtime exception because numbers[0] is being read before being initialized.

C.      The program will compile and prints null when executed.

D.     The program will compile and print 0 when executed.

E.      The program will compile and print undefined when executed.

F.       The program will compile and run but the results are not predictable because of the array is un-initialized.

 

 

8.    Consider the following code. What will happen when you execute this code?

 

                                                        1.            public class MultiArrayTest {

                                                        2.             

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

                                                        4.              int[][][] a = new int[3][][];

                                                        5.              a[0] = new int[5][];

                                                        6.              a[2] = new int[2][];

                                                        7.              for (int i = 0; i < a.length; i++) {

                                                        8.                for (int j = 0; j < a.length; j++) {

                                                        9.                  System.out.println("executing... ");

                                                     10.                }

                                                     11.              }

                                                     12.             }

                                                     13.             

                                                     14.            }

 

G.     The program will not compile because a[1] is not initialized.

H.     The program will compile and prints “executing...” 10 times.

I.        The program will compile and prints “executing...” 3 times.

J.        The program will compile and prints “executing...” 9 times. 

K.     The program will compile and but will not print anything.

L.      The program will compile and run but the results are not predictable because of the array is un-initialized.