Menu
Topics Index
...
`

Method Declaration


If you need explanation Read this topic

If you need Answer Take test on this topic

Method Declaration
What will be the output of the following program?
public class Global {
    static Integer number;
    public static void myFunction(Integer x) {
        ++x;
        System.out.println(x);
    }
    public static void main(String arg[]) {
        myFunction(number);
    }
}

A. 1
B. 0
C. Compilation Error
D. Runtime Error 
Topic: Java Number Class

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is D.
because number variable holds null value. So we are incrementing a null variable which causes NullPointerException.

Posted by Gopinath Manchikanti    2014-09-04 12:47:07


D ,,, null pointer exception

Posted by Raju VarshnEy    2014-09-04 12:49:28


Ans: D  Because Integer reference contains "null" value  "null" while incrementing null we will get NullPointerException

Posted by Indrasena Reddy    2014-09-04 12:50:04


D

Posted by Rakesh Vallamkonda    2014-09-04 13:56:03


Congratulations Gopinath Manchikanti. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-09-05 05:21:03


© meritcampus 2019

All Rights Reserved.

Open In App