IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

Java Programming - Flow Control - Discussion

@ : Home > Java Programming > Flow Control > Finding the output - Discussion

Read more:

"Forgiveness is a virtue of the brave."
- Indira Gandhi
1. 

What will be the output of the program?

int i = l, j = -1; 
switch (i) 
{
    case 0, 1: j = 1; /* Line 4 */
    case 2: j = 2; 
    default: j = 0; 
} 
System.out.println("j = " + j); 

[A]. j = -1[B]. j = 0
[C]. j = 1[D]. Compilation fails.

Answer: Option A

Explanation:

The case statement takes only a single argument. The case statement on line 4 is given two arguments so the compiler complains.


Binod said: (Wed, Jun 22, 2011 04:29:17 PM)    
 
I am not getting it. Please make me understood. How the loop goes.

Irfan said: (Thu, Jul 28, 2011 12:06:56 PM)    
 
The above statement is correct if you write it this way.

switch (i)
{
case 0:
case 1: j = 1;
case 2: j = 2;
default: j = 0;
}

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!