Menu
Topics Index
...
`

Static variables and Boolean1899


If you need explanation Read this topic

If you need Answer Take test on this topic

Static variables and Boolean1899
What will be the output of the following program?
public class Programming {
    static boolean b;
    static int[] ary = new int[1];
    static char chr;
    static boolean[] boolarr = new boolean[1];
    public static void main(String args[]) {
        boolean a = false;
        if (b) {
            a = (chr == ary[chr]);
        } else {
            a = (boolarr[chr] = b);
            System.out.println(a + " " + boolarr[chr]);
        }
    }
}

A. true true
B. false false
C. true false
D. false true
E. Compilation Error or Runtime Error
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.

its not default value @ sneha
static boolean variable got initialized as false..
so else part works...
here b value set to boolarr[chr]..then this set to a ...so both have the value false
so ans : b

Posted by Ananda Kumar    2014-05-05 05:56:46


Ans is E..we cant use variblw without initilization

Posted by Uday Kumar    2014-05-05 07:43:12


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

Posted by Merit Campus    2014-05-06 04:23:12


© meritcampus 2019

All Rights Reserved.

Open In App