public class SwitchTrial { final static short caseVal = 2; public static void main(String[] abc) { for (int iterNo = 0; iterNo < 3; iterNo++) { switch (iterNo) { case caseVal: System.out.print(“a “); case caseVal – 1: System.out.print(“b “); case caseVal – 2: System.out.print(“c “); } } } Answer: Output: c b c a b c Since caseVal is declared as
Read More
Flow Controls and Assertions
What would be the output if boolA is false and boolB is true?
public void foo(boolean boolA, boolean boolB) /* Line 1 */ { if (boolA) /* Line 3 */ { System.out.println(“X”); /* Line 5 */ } else if (boolA && boolB) /* Line 7 */ { System.out.println(“X && Y”); /* Line 9 */ } else /* Line 11 */ { if (!boolB) /* Line 13 */ {
Read More