Menu
Topics Index
...
`

AccessVariables test


If you need explanation Read this topic

If you need Answer Take test on this topic

AccessVariables test
What will be the output of the following program?
public class AccessVariables {
    private static final boolean BOOLEAN = true;
    private static final boolean BOOLEAN2 = BOOLEAN;
    static boolean b1, b2;
    public static void main(String... args) {
        int b = 0;
        if (!b1)
            if (!b2) {
                b1 = true; b++;
                if (5 > 6) b++;
                if (!b1) b = b + 10;
                else {
                    if (b2 = BOOLEAN2) b = b + 100;
                    else if (b1 | b2) b = b + 1000;
                }
            }
        System.out.println("Number = " + b);
    }
}

A. Number = 0
B. Number = 4
C. Number = 101
D. Number = 111
E. Compilation Error or Runtime Error
Topic: Other Advanced Topics 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 C, since first 2 inner ifs are not traversed through.

Posted by Nagesh Goud Anthati    2013-05-24 12:39:07


ans is c....intialy b1,b2 r false...dn b1 bcums true...dn it goes to else where b2 bcums true and b=101

Posted by Santosh Munugota    2013-05-24 12:49:43


ans is c bcoz b2=BOOLEAN2 is assignmnt n does not check for equality.. other parts dont need an xplanation.. :)

Posted by Pramod Jain    2013-05-24 12:52:32


option c default values of booleam are false

Posted by Ramkumar Boggarapu    2013-05-24 12:52:54


ans is E bcz we can store true or false in boolean variable BOOLEAN2

Posted by Indrasena Reddy    2013-05-24 12:59:00


option c default values of booleam are false  

initially
b1=b2=false;
BOOLEAN=BOOLEAN2=true
int b=0;
if(!b1)  //true
if (!b2 )   //true
{
    b1=true ;
    b++;         //b=1;
    if (5>6)       //false
        b++;
    if(!b1)  //false else will execute
        b=b+10;
    else
    {
        if (b2=BOOLEAN2) //it initialise ant checks  it becomes true
                b=b+100;  //b=101
        else if (b1  | b2)        //false
            b=b+1000;        
    }
}

number=101

Posted by Ramkumar Boggarapu    2013-05-24 12:59:08


Congratulations Santosh Munugota. You are today's daily dose winner. Please send us your mobile details and we will process the recharge on Monday after considering the new likes.

Posted by Merit Campus    2013-05-25 02:39:15


got rc :)

Posted by Santosh Munugota    2013-05-27 14:51:26


© meritcampus 2019

All Rights Reserved.

Open In App