SCJP Module-1 Question-2


 

SCJP Module-1 Question-2

This program will trace your knowledge of Java, and helps in preparation for SCJP examination.

This program will trace your knowledge of Java, and helps in preparation for SCJP examination.

What is the output of the following code when compiled and run?

1. public class Question2 {
2. public static void main(String[] args){
3. int x,y,z;
4. y=1;
5. x=z=1;
6. System.out.println(y+","+x+","+z);
}
}

Select correct answers

(1) Prints 1,1,1
(2) Error during compilation at line 3
(3) Prints 0,0,1
(4) Error during compilation at line 5
(5) Error during compilation at line 6

Answer-2

(1)

Explanation:

It will print 1,1,1. Writing operator + to the suffix of variable wont generate any error and also not increment the value of variables.

Ads