Page 1 of 1

Exam Guide 1Z0-815 - Deshmukh,Hanumant - Pg 266

Posted: Tue Jul 14, 2020 11:13 am
by nirpacc
public class TestClass {
public static void main(String[] args){
int i = 0;
switch(args[0]) { default : i = i + 3;
case "2" : i = i + 2;
case "0" : break;
case "1" : i = i + 1;
}
System.out.println("i is "+i);
}
}

when I run, java TestClass 0.
output is 0. I am assuming control goes to case "0" and it comes out.

when I run, java TestClass 1
output is 1. I think control goes to case "1", but isn't it suppose to fall through to case "2", and default since there is no break statement in case "1".

can you please let me know what I am missing here?
Thank you.

Deshmukh, Hanumant. OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815: Study guide for passing the OCP Java 11 Developer Certification Part 1 Exam 1Z0-815 (p. 266). Enthuware. Kindle Edition.

Re: Exam Guide 1Z0-815 - Deshmukh,Hanumant - Pg 266

Posted: Tue Jul 14, 2020 1:24 pm
by admin
Well , it is called "fall" through because the control falls i.e. drops below, when there is no break. It doesn't go up.

Re: Exam Guide 1Z0-815 - Deshmukh,Hanumant - Pg 266

Posted: Wed Jul 15, 2020 8:28 am
by nirpacc
Thank you very much.