Share on Google+Share on Google+

SCJP Module-7 Question-8

Advertisement
This program will test your knowledge about the constructor and Integer class in Java. It will also test your understanding about the flow of program in Java.

Given a sample code:

1    public class Test {
2    int a = 1;
3    int b;

4    public Test(Integer x) {
5    b = a + x;
6    System.out.println(b);
    }

7    public static void main(String[] args) {
8    new Test(new Integer(4));
}}

What will be the result of above code ?

(A) 5
(B) An exception is thrown at runtime.
(C) Compilation fails because of an error on line 4.
(D) Compilation fails because of an error on line 8.

Answer:

(A)

Advertisements

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