Mock interview-2
Source: Dev.to
Interview Questions
- Tell me about yourself?
- Why move from Mechanical Engineering to IT?
- If Mechanical Engineering was your first choice, why choose an IT course now?
- Why Java?
- Is Java easy?
- What does compiling a program involve?
- What happens during execution?
- How can you produce output without using
System.out.println()? - What does
System.out.println()output? - What are control‑flow statements?
- What is a
switchcase?
Example 1
switch (x) {
case 1:
System.out.print("One ");
case 2:
System.out.print("Two ");
case 3:
System.out.print("Three ");
default:
System.out.print("Default");
}
Output: Two Three Default
Example 2
switch (x) {
default:
System.out.print("Default ");
case 1:
System.out.print("One ");
case 2:
System.out.print("Two ");
}
Output: Default One Two
Example 3
switch (ch) {
case 'A':
System.out.println("A");
break;
case 65:
System.out.println("Sixty Five");
}
Output: A
(The 'A' case matches; 65 is treated as an int.)
Example 4 (switch expression)
String result = switch (day) {
case 1 -> "Monday";
case 2 -> "Tuesday";
case 3 -> "Wednesday";
default -> "Invalid";
};
System.out.println(result);
Output: Wednesday