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.
Exam Guide 1Z0-815 - Deshmukh,Hanumant - Pg 266
Moderator: admin
-
- Posts: 2
- Joined: Thu Jul 09, 2020 10:47 am
- Contact:
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Exam Guide 1Z0-815 - Deshmukh,Hanumant - Pg 266
Well , it is called "fall" through because the control falls i.e. drops below, when there is no break. It doesn't go up.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Thu Jul 09, 2020 10:47 am
- Contact:
Re: Exam Guide 1Z0-815 - Deshmukh,Hanumant - Pg 266
Thank you very much.
Who is online
Users browsing this forum: No registered users and 246 guests