Home » JAVA Programming » Characters » Question
  1. What will be output of the following code?

    public class Result
    {
    Integer K;
    int p;
    public Result(int q)
    {
    p = K+q;
    System.out.println(p);
    }
    public static void main(String[] args)
    {
    new Result (new Integer(8));
    }
    }
    1. A NullPointerException occurs at runtime
    2. The value “8” is printed at the command line
    3. An IllegalStateException occurs at runtime
    4. Compilation fails because of an error in line
    5. None of these
Correct Option: C

Because we are performing operation on reference variable which is null.



Your comments will be displayed only after manual approval.