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));
}
}
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: Option D
Related Questions on Strings
In Java, which class is used to represent a sequence of characters as a string?
A. String
B. StringBuilder
C. StringSequence
D. StringArray
What is the correct way to create a new empty String object in Java?
A. String emptyString = "";
B. String emptyString = new String();
C. String emptyString = " ";
D. String emptyString = null;
E. Both A and B
Which of the following methods is used to compare two strings for equality in Java?
A. equals()
B. compareTo()
C. equalsIgnoreCase()
D. compare()
Join The Discussion