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
Joined: Nov 22, 2008
Posts: 18944
posted
0
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
Joined: Jan 30, 2000
Posts: 18652
posted
0
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.
"I'm not back." - Bill Harding, Twister
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
posted
0
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
Joined: Jan 31, 2000
Posts: 1467
posted
0
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
Joined: Sep 14, 1999
Posts: 2813
posted
0
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