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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
nirpacc
Posts: 2
Joined: Thu Jul 09, 2020 10:47 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

nirpacc
Posts: 2
Joined: Thu Jul 09, 2020 10:47 am
Contact:

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

Post by nirpacc »

Thank you very much.

Post Reply

Who is online

Users browsing this forum: No registered users and 246 guests