Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Mock Exam No: 3 question 46

 
sreelakshmi sarma
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following statements are true?
1) A method cannot be overloaded to be less public in a child class
2) To be overriden a method must have the same name and parameter types
3) To be overriden a method must have the same name, parameter and return types
4) An overriden method must have the same name, parameter names and parameter types
I thought 2&3 are correct. But the answer given is only 3. Why not 2??
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2) is not true because the return type of the overriden method must be the same type as the overriding method, it only says about the name and the parameter types and not the return type. So you cannot consider this option. This has to be considered when you are overriding a method.
Hope this helps!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sree- you are correct. I think that Marcus was thinking that #2 meant that the return type does not have to be the same for an overridden method. Which would be false. But that's not what it says, and 2 is true as written. I'm moving this to Mock Exam Errata.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that other requirements for overriding are that the overriding method cannot be more private, and it cannot throw checked exceptions unless they were declared in the overridden method. Neither 2 nor 3 mention these requirements - does that mean they're both wrong? No, it means that neither one is a complete list of requirements. But neither one claimed to be complete. The requirements that are listed in 2 and 3 are all correct, and so both answers are correct.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says Which of the foll. are true? . Both 2) and 3) are individually correct. If it would have asked 'select the MORE SUITABLE ans from this list' then only 3) will be correct I think. One more point about the Overriding is the no & type & order of parameters of the overriding method also MUST be SAME that of the overridden one.
regds
maha anna

[This message has been edited by maha anna (edited April 05, 2000).]
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think option 2 taken on its own is true (ie my answer is incorrect) . Overriding does involve more than those requirments but if you do not meet those requirements then you cannot have overriding. Don't forget I always try to include both an answer and explanation (sometimes wildly incorrect of course), so check that out when you wonder what I was thinking of.
I appreciate all comments on my questions and am interested in ambiguities as well as plain incorrect stuff.
I am still building (and correcting exam 3) and I have a few more questions on my hard disk at home that will appear real soon now.
Marcus
Marcus

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic