Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following Java code?
public class Boxer1
{
Integer i;
int x;
public Boxer1(int y)
{
x = i+y;
System.out.println(x);
}
public static void main(String[] args)
{
new Boxer1 (new Integer(4));
}
}

What will be the output of the following Java code?
public class Boxer1
{
Integer i;
int x;
public Boxer1(int y)
{
x = i+y;
System.out.println(x);
}
public static void main(String[] args)
{
new Boxer1 (new Integer(4));
}
}
a) The value “4” is printed at the command line
b) Compilation fails because of an error in line
c) A NullPointerException occurs at runtime
d) An IllegalStateException occurs at runtime

Answer: d
Explanation: Because we are performing operation on reference variable which is null.

Join The Discussion