Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Roberts/Heller/Ernest Ch. 6 questions 1 & 2 (pp. 192-3)  RSS feed

 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberts/Heller/Ernest Ch. 6 questions 1 & 2 (pp. 192-3):
I'm not going to bother typing in both questions, but they both ask about lists of possible function declarations (either overloads or overrides), and ask which ones are legal. An example is:
<code><pre>A. public int aMethod(int a, int b) { }</pre></code>
All the given answers for both questions are incorrect, because all the methods are declared with non-void return types, yet none of the methods contains a return statement. In order for the given answers to make sense, pretend that each method contains a "return 0;", as in:
<code><pre>A. public int aMethod(int a, int b) { return 0; }</pre></code>
(or some other code, any other code as long as it contains a return using a suitable data type.)
This may be an obvious error such that people can easily tell what RHE really meant by the question, but it annoys me that I told them about this 3 reprintings ago, yet they still haven't included it in their errata.
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim
Thanks for observing it and bringing it to everyone's notice. That was a sharp observation but it helps us to keep this point in mind in the real exam.
Thanks.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
I agree with you. If you don't specify the return statement with the suitable return type, it won't compile. But if this type of Question comes in the exam, how can we be sure that it's not asking us to test for the suitable modifiers, position of the return type etc. If we are asked to choose the legal method definitions, should we not pick this one?.
public int aMethod(int a){}
Can you please clear my doubt regarding this.
Regards,
Kiran.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!