JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
18 / 64
Choose the correct option.
public class SwitchTest {
public static void main(String argv[]) {
SwitchTest ms=new SwitchTest();
ms.display();
}
public void display() {
int k=10;
switch(k){
case 10:
System.out.println("10");
case 30:
System.out.println("30");
case 20:
System.out.println("20");
default:
System.out.println("40");
}
}
}
public class SwitchTest {
public static void main(String argv[]) {
SwitchTest ms=new SwitchTest();
ms.display();
}
public void display() {
int k=10;
switch(k){
case 10:
System.out.println("10");
case 30:
System.out.println("30");
case 20:
System.out.println("20");
default:
System.out.println("40");
}
}
}
A10 ,30 , 20 , 40
B10 ,30 , 20
C10
D10, 40
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
It prints 10,30,20,40
As there is no break in the switch case
Read Full Answer
Report Error
Please Login First Click Here
STEP-BY-STEP
There is no break statement after each case. When the argument inside the switch matches it's respective case, that particular case gets executed, and the rest of the cases also gets executed alongwith. This is the reason because of which each of the cases are getting executed one after the other, even the default case gets executed.
Read Full Answer
Report Error
Please Login First Click Here