This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Ranch Office and the fly likes Wrong answer in the JavaRanch Rule Round-up Game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "Wrong answer in the JavaRanch Rule Round-up Game" Watch "Wrong answer in the JavaRanch Rule Round-up Game" New topic
Author

Wrong answer in the JavaRanch Rule Round-up Game

Sergey Zakusov
Greenhorn

Joined: Jun 10, 2010
Posts: 3
Question #135 should be corrected.

Answer can be "false" because there is no information about break statement.
So the default statement will execute even a case value matches switch() argument, for example:




[Thumbnail for javaranch_game2_135.png]

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

From where you get this question. This is not the right forum to post it. What is the complete question? Because if no match found then also default case will be executed.


Life is easy because we write the source code.....
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch, and thanks for the feedback!

I believe the answer is correct as it stands. It says that the default clause will execute if no case matches, and that's absolutely true. It's possible that the default will execute if a case matches, also -- but that doesn't make the original statement false. If the question had said "True or false: the default clause will only execute if no case matches", then I would agree with you, but it does not say that.


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Pramod P Deore wrote:This is not the right forum to post it.


As he says in the subject line, it's from the JavaRanch Rules Roundup Game, and this is absolutely the right place to post this.
Sergey Zakusov
Greenhorn

Joined: Jun 10, 2010
Posts: 3
Pramod P Deore wrote:From where you get this question.

http://www.javaranch.com/game/game2.jsp

Pramod P Deore wrote:This is not the right forum to post it.

Paul Wheaton said me to post it here.

Pramod P Deore wrote:What is the complete question? Because if no match found then also default case will be executed.

It's not a question. It's just a proposal.
Sergey Zakusov
Greenhorn

Joined: Jun 10, 2010
Posts: 3
Ernest Friedman-Hill wrote:If the question had said "True or false: the default clause will only execute if no case matches", then I would agree with you, but it does not say that.

Ok. You are right.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Hi, Sergey , Actually I don't know about the JavaRanch Rule Round-up Game therefore I had asked that questions. but now I got my mistake. Thanks I will also check JavaRanch Rule Round-up Game.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

Sergey Zakusov wrote:Ok. You are right.
EFH usually is.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrong answer in the JavaRanch Rule Round-up Game
 
Similar Threads
switch case
What is this?
Something is missing in my Switch method
switch doubt..
default statement