Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return statement

 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I have a few problems understanding this question (from Glenn, Mitchell. OCAJP Oracle Certified Associate Java SE 8 Programmer Practice Exams (Kindle Locations 12152-12153). Enthuware. Kindle Edition. )

Which of the following implementations of a max() method will correctly return the largest value?

A.



B
C.
D.

E. None of the above.


my answer was B but apparently it was D.
I don't seem to understand why B is wrong, any idea? It returns an int as it is supposed to be, so what's wrong with it? Why is D correct and not B?
thanks!




 
Stephan van Hulst
Bartender
Pie
Posts: 6503
83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return statement must be called with an expression if the method is not void. The if-statement is not an expression, meaning it doesn't return a value.
 
Liutauras Vilda
Bartender
Pie
Posts: 2792
112
BSD VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Attin wrote:my answer was B
What is your reasoning about A being wrong then? Well, never mind.

However, that answer B as a first character in its question contains illegal symbol . (dot), which on itself should prevent code from compiling without even looking further what is written there.
 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood, thanks, I think the fact that it's inside a return statement confused me.
What is your reasoning about A being wrong then?
Because this is essentially meaningless
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic