Home » JAVA Programming » Variable Types » Question
  1. What is the output of this program?

    public class scope_var
    {
    public static void main(String args[])
    {
    int a;
    a = 5;
    {
    int b = 6;
    System.out.print(a + " " + b);
    }
    System.out.println(a + " " + b);
    }
    }
    1. Compilation error
    2. 5 6 5 6
    3. 5 6 5
    4. Runtime error
    5. None of these
Correct Option: A


scope_var.java:11: error: cannot find symbol
System.out.println(a + " " + b);
^
symbol: variable b
location: class scope_var
1 error



Your comments will be displayed only after manual approval.