Menu
Topics Index
...
`

Static variables and Boolean


If you need explanation Read this topic

If you need Answer Take test on this topic

Static variables and Boolean
What will be the output of the following program?
public class Boolean {
    private boolean myFlag1 = true;
    private static final boolean myFlag2;
    static final double weeks = 9.5;
    protected static final int BOXWIDTH = 42;
    public static void main(String[] arguments) {
        Boolean m = new Boolean();
        System.out.println(m.myFlag1);
        System.out.println(myFlag2);
        System.out.println(weeks);
        System.out.println(BOXWIDTH);
    }
}

A. true
false
9.5
42
B. false
false
9.5
42
C. true
ture
9.5
42
D. Some other output
E. Compilation Error or Runtime output
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.

e is answer since the myFlag2 is not initialised

Posted by Karteek Paruchuri    2013-10-30 09:06:40


Ans is E.. since myFlag2 is not intialized.. so that leads to compilation error..  variable must be intialized when it is declared as final..

Posted by Om Prakash Om    2013-10-30 10:08:58


Ans is A...whenever the variable is declared as static whether it is final or private..it gets initialized to zero/false(boolean)...therefore here,myFlag2 gets initialised to false...

Posted by Sneha Rapool    2013-10-30 14:42:59


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

Posted by Merit Campus    2013-10-31 03:46:13


© meritcampus 2019

All Rights Reserved.

Open In App