I forget: what is the rule for method overriding?

I

iamzeus

Well, a normal use is a subclass method overriding the more general
method of its superclass with a method specific to that subclass. Is
this what you're referring to? It's not really a rule.

Mike Lewis
Grinnell College
 
O

Oliver Wong

puzzlecracker said:
There is something about being more specific and general?

what are those?

The overriding method has to be able to handle every situation the
overridden method can handle, the the overriding method has to be usable in
every situation the overridden method could have been used.

Therefore, the parameters have to be of the same type, or of a more
general type (so that it can handle everything the old method could handle
and more), and the return value has to be of the same type, or a more
specific type (so that anything that could handle the old return value can
also handle the new one).

- Oliver
 
S

Sashi

Oliver said:
The overriding method has to be able to handle every situation the
overridden method can handle, the the overriding method has to be usable in
every situation the overridden method could have been used.

Therefore, the parameters have to be of the same type, or of a more
general type (so that it can handle everything the old method could handle
and more), and the return value has to be of the same type, or a more
specific type (so that anything that could handle the old return value can
also handle the new one).

- Oliver

Also, the overriding method should not throw exceptions that are more
general than the one in the parent class and also it should not throw
any exceptions not declared in the method in the parent class.
Sashi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top