Menu
Topics Index
...
`

Creating Static variable


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Static variable
What will be the output of the program?
public class Karbon {
    static int i = 5;
    public static void main(String[] args) {
        Karbon test = null;
        System.out.print("i = " + test.i + ", ");
        System.out.print("i = " + Karbon.i);
    }
}

A. i = 0, i = 5
B. i = 5, i = 5
C. Compilation Error
D. NullPointerException
E. Runtime Error for some other reason
Topic: Static Keyword In Java

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.
becoz we didn't created object for "test" variable. but we are using it to retrieve the data

Posted by Gopinath Manchikanti    2014-07-09 12:57:20


Ans is B..
in test value of i is 5
as i is static so it can also be called by class name...i=5 i=5...
static variables do not require instantiated object to be called...

Posted by Mânïshå Mùlchåndânï    2014-07-09 13:09:08


B bcoz is i is static so we can not need create object for class

Posted by Rathod Ajay    2014-07-09 15:19:26


B sataic is load at class tme so it can give sme value fr both

Posted by Dinesh Saini    2014-07-09 19:42:54


Congratulations Mânïshå Mùlchåndânï. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-10 04:28:04


b

Posted by Bhuvaneswari Bhuvana    2014-07-10 13:38:18


© meritcampus 2019

All Rights Reserved.

Open In App