Computer Applications
Consider the following program segment and select the output of the same when n = 10 :
switch(n)
{
case 10 : System.out.println(n*2);
case 4 : System.out.println(n*4); break;
default : System.out.println(n);
}
- 20
40 - 10
4 - 20, 40
- 10
10
Java Conditional Stmts
ICSE 2023
22 Likes
Answer
20
40
Reason — Since n = 10, case 10 will be executed. It prints 20 (10 * 2) on the screen. Since break statement is missing, the execution falls through to the next case. Case 4 prints 40 (10 * 4) on the screen. Now the control finds the break statement and the control comes out of the switch statement.
Answered By
11 Likes
Related Questions
The code obtained after compilation is known as:
- source code
- object code
- machine code
- java byte code
Missing a semicolon in a statement is what type of error?
- Logical
- Syntax
- Runtime
- No error
A method which does not modify the value of variables is termed as:
- Impure method
- Pure method
- Primitive method
- User defined method
When an object of a Wrapper class is converted to its corresponding primitive data type, it is called as …………… .
- Boxing
- Explicit type conversion
- Unboxing
- Implicit type conversion