Share on Google+Share on Google+

SCJP Module-1 Question-2

Advertisement
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.

Advertisements

Posted on: July 5, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.