What will be the output of the following Java program? a) 0 b) 1 c) true d) false

What will be the output of the following Java program?

class mainclass {
        public static void main(String args[]) 
        {
            boolean var1 = true;
	    boolean var2 = false;
	    if (var1)
	        System.out.println(var1);
	    else
	        System.out.println(var2);
       } 
    }

a) 0 
b) 1 
c) true 
d) false

Answer: d
Explanation: boolean ‘&’ operator always returns true or false. It returns true when both the values are true and false otherwise. Since, var1 is defined true and var2 is defined false hence their ‘&’ operator result is false.

Previous Post Next Post