Computer Certification

  1. Home
  2. Computing & Technology
  3. Computer Certification

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);    

}

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

Back to beginning
| Next Question



Explore Computer Certification

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Computer Certification

  1. Home
  2. Computing & Technology
  3. Computer Certification

©2009 About.com, a part of The New York Times Company.

All rights reserved.