Java.lang Class

Q1: What will be the output of the program?
public class ExamQuestion6 
{
    static int x; 
    boolean catch()
    {
        x++; 
        return true; 
    } 
    public static void main(String[] args)
    {
        x=0; 
        if ((catch() | catch()) || catch()) 
            x++; 
        System.out.println(x); 
    } 
}

A 1

B 2

C 3

D Compilation Fails

ANS:A - 1

Initially this looks like a question about the logical and logical shortcut operators '|' and '||' but on closer inspection it should be noticed that the name of the boolean method in this code is 'catch'. 'catch' is a reserved keyword in the Java language and cannot be used as a method name. Hence Compilation will fail.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.