Class polymorphism is the most important feature that supports object-oriented languages. People who have experience in non-object-oriented language development usually refer
The content may be hard to get used to, because many people mistakenly think that the encapsulated language of the Support class supports object-oriented, but it is not,Visualized BASIC 6.0
It is a typical non-object-oriented development language, but it is indeed a Support class. The support class cannot be described as a language that supports object-oriented and can solve polymorphism problems, is a language that truly supports object-oriented development.
Be sure to remind readers of other non-object-oriented language basics!
The concept of polymorphism is a bit vague. If you want to use clear language descriptions at the beginning
It seems unrealistic for the reader to understand it, so let's look at the following code first:
//
Routine 1
# Include <iostream
>
Using
Namespace
STD;
Class
Vehicle
{
Public
:
Vehicle (float
Speed, int
Total)
{
Vehicle: speed = speed;
Vehicle: total = total;
}
Void
ShowMember ()
{
Cout
<Speed <"|" <total <endl;
}
Protected
:
Float
Speed;
Int
Total;
};
Class
Car: public
Vehicle
{
Public
:
Car (int
Aird, float
Speed, int
Total): Vehicle (speed, total)
{
Car: aird = aird;
}
Void
ShowMember ()
{
Cout
<Speed <"|" <total <"|" <aird <endl;
}
Protected
:
Int
Aird;
};
Void
Main
()
{
Vehicle a (120,4 );
A. ShowMember ();
Car B (180,110, 4 );
B. ShowMember ();
Cin
. Get ();
}
In c ++, the derived class is allowed to overload the base class member function.
Specifically, when calling the member functions of different classes of objects, the system knows how to find members with the same name of the class,. showMember ();, that is, call
Is Vehicle: ShowMember (), B. ShowMember ();, that is, the Car: ShowMemeber (); is called ();.