Artifact [e3c746c7dc]
Not logged in

Artifact e3c746c7dc5fd47592d4aeeb0b3196c51ce05737:

Wiki page [Overriding base class methods] by Les Farrell 2013-01-18 22:49:52.
D 2013-01-18T22:49:52.343
L Overriding\sbase\sclass\smethods
P 6012d5df7aa2ad66fcef87a0ec04524934937f10
U Les\sFarrell
W 1287
<p><i><font size="3"><b>Overriding base class methods</b></font></i></p>

<p><i><font size="3">A derived class can declare a method to override a method
in its base class. The method declaration in the derived class must exactly
match the method in the base class in order to override it. That means it must
have the same return type, name, arguments and the const keyword if it has been
used.</font></i></p>

<p><i><font size="3">Care must be taken when overriding base class methods to
avoid unintentionally hiding overloaded methods - a single overriding method in
a derived class will hide all overloaded methods of that name in the base
class!</font></i></p>

<p><i><font size="3">For instance, the base <b>Mammal </b>class, listed below,
contains two overloaded methods named walk. These require no argument and one
argument respectively. The derived Cat class, listed on the opposite page,
creates an overriding method named <b>walk</b>, with no arguments. This hides
both <b>walk </b>methods in the base class.</font></i></p>

<p><i><font size="3">Additionally the <b>Cat </b>class contains a method named
<b>speak </b>that will override the method of the same name in the <b>Mammal
</b>base class whenever it is called from the main program.</font></i></p>

<p><i><br>
</i></p>

Z 7c6bfbbe6a3ca4c751fe246ba4fbb28b