Home » JAVA Programming » Object & Classes » Question
  1. What is the output of this program?

    public class main_class_Example
    {
    public static void main(String args[])
    {
    int p = 10;
    if (p == 10)
    {
    // int p = 20;
    int q = 20;
    System.out.println(q);
    }
    }
    }
    1. 10
    2. 20
    3. 11
    4. 21
    5. 25
Correct Option: B

Two variables with the same name can’t be created so there is second variable q in a class.
output: 20



Your comments will be displayed only after manual approval.