info@meritcampus.com    +91-85006-22255
...
`

BoolArray
What will be the output of the following program?
`class BoolArray {    boolean[] bool = new boolean[3];    int count = 0;    void set(boolean[] x, int i) {        x[i] = true;    ++count;    }    public static void main(String[] args) {        BoolArray result = new BoolArray();        result.set(result.bool, 0);        result.set(result.bool, 2);        result.check();    }    void check() {        if (bool[0] && bool[1] | bool[2])            count++;        if (bool[1] && bool[(++count - 2)])            count += 7;        System.out.println("count = " + count);    }}`

 A. count = 0 B. count = 2 C. count = 3 D. count = 7 E. Compilation Error or Runtime Error
Topic:

### User comments below.All of them might not be correct.

option c is the answer since the and & or operation in check method gave the resulting cnt as 3

Posted by Prudhvi Paidipally    2013-05-10 12:39:56

ans is c: bool[0] and bool[2] are set to true n count is incremented twice so count becomes 2 then check is caled where the first if block is evaluated as bool[0] && bool[1] even if it gives false or true bool[2] is true so count is incremented again making count 3 the next if block is not addressed as bool[1] is not true

Posted by Krishna Murthy    2013-05-10 12:43:18

option c is the answer. the "and/OR" operations on the bool array values decide the output of the count value in the check method

Posted by Karteek Paruchuri    2013-05-10 12:46:55

answer is c...bcoz bool array hav true false true after setting the values and count is 2..nxt check method is called where first if gets executed so count is incremented by 1 and the second if condition remains false bcoz bool[1] is false and fiinally the value of count is printed as 3

Posted by Pramod Jain    2013-05-10 12:47:11

Congratulations Krishna Murthy, 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-10 15:22:19

thanku MC received rc :) :)

Posted by Krishna Murthy    2013-05-16 13:20:36