Question 219 / 297:  What is the possible result of compiling and running the following code?
public class Test implements Runnable {

Integer id;

public static void main(String[] args) {

new Thread(new Test()).start();

new Thread(new Test()).start();

}

public void run() {

press(id);

}

synchronized void press(Integer id) {

System.out.print(id.intValue());

System.out.print((++id).intValue());

}

}

A  0101
B  0011
C  -10-10
D  -1-100
E  compilation error
F  an exception is thrown at run time
<< First < Previous Next > Last >>
Explanation:

A NullPointerException is thrown at runtime, because of invoking method intValue() on a non initialized Integer id.

Exam Home Page
Ask
Darlene Paliswat
Start Test
Tess Armstrong
Start Quiz
Stephanie Redfern
Start Quiz
Danielle Stephens
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>