Share on Google+Share on Google+

SCJP Module-1 Question-28

Advertisement
The Sample program given below will test your understanding about the Java program logic.

Given a sample code:

class Test1 {
public static void main(String[] args) {
int x = 1;
Test1 p = new Test1();
p.plusX(x);
System.out.print(" main x = " + ++x);
}

void plusX(int x) {
System.out.print(" plusX x = " + x++);
}
}

What will be the result? Choose the correct option?

(A) plusX x = 1 main x = 2
(B) plusX x = 2 main x = 2
(C) plusX x = 2 main x = 1
(D) plusX x = 1 main x = 1

Answer:

(A)

Advertisements

Posted on: July 21, 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.