JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
20 / 64
What will be the output of the below code segement:
public class SwitchTest {
public static void main(String argv[]) {
SwitchTest ms=new SwitchTest();
ms.display();
}
public void display() {
int k=10;
switch(k){
default:
System.out.println("This is the default output");
break;
case 10:
System.out.println("ten");
break;
case 20:
System.out.println("twenty");
break;
}
}
}
public class SwitchTest {
public static void main(String argv[]) {
SwitchTest ms=new SwitchTest();
ms.display();
}
public void display() {
int k=10;
switch(k){
default:
System.out.println("This is the default output");
break;
case 10:
System.out.println("ten");
break;
case 20:
System.out.println("twenty");
break;
}
}
}
Aten
Btwenty
Cten twenty
DNone
Answer: Option (Login/Signup)
Show Explanation
The switch takes the argument or the choice as k, or 10.
Hence, case 10 gets executed, and we get the output as ten.
Asked In ::
STEP-BY-STEP
From the main() method when the control comes to the display() method, we find that k is initialized with value 10, after which we see a switch-case statement.
The switch takes the argument or the choice as k, or 10.
Hence, case 10 gets executed, and we get the output as ten.
Read Full Answer
Report Error
Please Login First Click Here