Assessment Test for Non-Java Programmer

Instructions: For each question, choose one single best answer. There is no time limit, so you can change your answers at any time. When you click Done button, the assessment report will appear in the next screen.

1.   Which of the following modifiers is used to declare a class variable?;

A.    protected
B.    private
C.    public
D.    static
E.    final

2.   Which of the following is a legal Java keyword?

A.    Integer
B.    assert
C.    String
D.    main
E.    option

3.   The returning of memory (to the operating system) occupied by objects that are no longer needed is automatically accomplished in Java by a feature commonly known as:

A.    destructor
B.    garbage recycling
C.    garbage collector
D.    garbage reclaimer
E.    memory collector

4.   Given code below. When you attempt to run it, what is the output?

1. class Test {
2.    public static void main(String[] ok){
3.        System.out.println(ok[0]);
4.     }
5. }

>java Test ok or not;
A.    Compile-time error
B.    ok
C.    or
D.    not
E.    Test

5.   What will happen when you attempt to compile and run the following code segment?

1. int output = 10;
2. boolean b1 = false;
4. if((b1) && ((output += 10) == 20)){
5.    System.out.println(output);
6. }
7. else {
8.    System.out.println(output);
9. }
A.    Compilation error, attempting to perform binary comparison on logical data type.
B.    Compilation error at line 4.
C.    Compilation and output of 20
D.    Compilation and output of 10

6.   Given the code below, what happens when you attempt to compile it?

 1. class Base {
 2.    void test() {
 3.        System.out.println("Base");
 4.    }
 5. }
 6. class Child extends Base {
 7.    void test( ){
 8.        System.out.println("Child");
 9.        super.test();
10.    }
11.    static public void main(String[] args) {
12.        new Child().test();
13.    }
14. }
A.    It cannot compile. The code at line 9 should be the first statement in the method.
B.    It cannot compile. The super should not be used to refer the super method at line 9.
C.    It compiles, runs and prints: Child and Base
D.    It compiles but cannot run.

7.   Given the code below, what happens when you attempt to run it?

 1. public class MyThread implements Runnable {
 2.    public void start () {
 3.        Thread myT = new Thread(this);
 4.    }
 5.    public void run() {
 6.        while(true) {
 7.           System.out.print(1);
 8.        }
 9.    }
10.    public static void main(String[] args) {
11.        MyThread myT = new MyThread();
12.        myT.start();
13.    }
14. }
A.    It runs well. Ones printed on the screen until you kill the thread by pressing ctrl-C.
B.    It runs. But code at line 7 will never be reached.
C.    It runs. But one will be printed out at least once.
D.    It runs. But code at line 7 will be called repeatedly with 0.01 second interval delay.
E.    The code itself doesn't compile.

8.   Which of the following code calculates intersection?
A.    Set x = new HashSet(set1);
B.    Set x = new HashSet(set1);
C.    Set x = new HashSet(set1);
D.    None of these.

Bug Report