The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 11:

What will be the result of executing the following code?

public static void main(String args[])
{
        char digit = 'a';
        for (int i = 0; i < 10; i++)
        {
              switch (digit)
              {
                    case 'x' :
                    {
                        int j = 0;
                System.out.println(j);        
                    }
                    default :
                    {
                        int j = 100;
                System.out.println(j);        
                    }
              }
       }
       
    int i = j;
       System.out.println(i);    
}

A. 100 will be printed 11 times.
B. 100 will be printed 10 times and then there will be a runtime exception.
C. The code will not compile because the variable i cannot be declared twice within the main() method.
D. The code will not compile because the variable j cannot be declared twice within the switch statement.
E. None of these.