Consider the following program and predict the output:
class Main {// ww w. j av a2 s.co m Integer I; int i; public Main(int i) { this.i = I + i; System.out.println(this.i); } public static void main(String args[]) { Integer I = new Integer(1); Main test = new Main(I); } }
d)
The member variable I is not initialized and accessed in the constructor, which results in a NullPointerException.
The main()
method declares a local variable named I whose scope is limited to the main()
method.