• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about Chapter 2 Question 20 on page 99 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Sangeetha Revanna
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How the output is greatgood though the case is 'B' and it does not match with case 'C'?
Output is only great right?

What is the result of the following code snippet?



a) great
b) greatgood
c) The code will not compile because of line 3.
d) The code will not compile because of line 6.
e) The code will not compile because of lines 6 and 9.

Boyarsky, Jeanne; Selikoff, Scott (2014-12-11). OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808 (pp. 99-100). Wiley. Kindle Edition.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sangeetha Revanna wrote:How the output is greatgood though the case is 'B' and it does not match with case 'C'?
Output is only great right?

No, the study guide is absolutely spot-on! The output of this code snippet is definitely greatgood. If it would have been a mistake in the study guide, it probably will already be on the official errata overview.

It seems you are missing some (important) concepts about the switch statement and therefore you are a bit surprised about the output. I'll provide you a tip and then you'll probably be able to answer your question yourself. What do you know about fall-through in switch statements?

Hope it helps!
Kind regards,
Roel
 
Sangeetha Revanna
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya sorry I got to know the answer for that.. Thank you..
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sangeetha Revanna wrote:Ya sorry I got to know the answer for that.

And can you explain us what fall-through in switch statements is all about and how it will affect the output in the code snippet you have posted?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic