Menu
Topics Index
...
`

Creating Static Arrays and Variables


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Static Arrays and Variables
What will be the output of the following program?
public class CanYouDoIt {
    static boolean bool;
    static int[] iary = new int[1];
    static char chr;
    static boolean[] barr = new boolean[1];
    public static void main(String args[]) {
        boolean b = false;
        if (bool) {
            b = (chr == iary[chr]);
        } else {
            b = (barr[chr] = bool);
            System.out.println(b + " " + barr[chr]);
        }
    }
}

A. false false
B. true true
C. false true
D. true false
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.

Answer is A,
Because static boolean bool default is false so if condition gets fail, else part executes barr[chr] is assigned asbool i.e false so false false will be printed.

Posted by Amar Kumar Biradar    2013-08-29 08:16:36


Congratulations Amar Kumar Biradar. You are this dose winner. Please send us your mobile details in a private message and we will process the recharge asap.

Posted by Merit Campus    2013-08-30 05:13:47


I have got recharge :)
Thanks Merit Campus :)

Posted by Amar Kumar Biradar    2013-08-31 10:39:44


© meritcampus 2019

All Rights Reserved.

Open In App