1. Unknown sensation
Many people learn to be polymorphic when they think.
The reason is unknown because of the polymorphism of the definition: the existence of a variety of forms of expression; Then, someone will overload (overload), overwrite (override), polymorphic variables and generics due to the same term "polymorphic". For example: Polymorphism (computer science)
yqj2065 thought: "(Preface page VII) as if Kong Yiji said" polymorphic this word has 4 kinds of writing ", in addition to highlight polymorphism of the term is more polymorphic, there is no theoretical significance and teaching significance, thus the book used a title-" 2.1.2 Ah, I see polymorphic ", To make polymorphic terms concise semantics. 】
In other words, when someone asks you what is polymorphic, I hope you will be able to answer concisely. Rather than let you say: "Well, polymorphic like water, can be fog, rainbow, waterfall ... A variety of expression patterns. There are 4 kinds of computer science.
The first kind ... "
2. Multi-state of onlookers
For example, there is a labor show, please butcher (abstract class butcher) performance of its technology. Butcher have sub-categories Plainbutcher and Twobbutcher.
static void Show (Butcher b) {//Show B.kill (); }
The general butcher--plainbutcher object, according to the general way kills the pig, but the individuality butcher--twobbutcher the object, kills the pig to kill the buttocks. So.
B.kill ();
There are a variety of performances or outputs at execution time.
- Polymorphic (polymorphism) is a pointer to the message receiver (polymorphic variable. such as B) to send the same message (such as Kill ()), you can get a different response.
- During the class. I told you. Suppose you have a simple answer to what is polymorphic when you test. You write:"Kill the pig to kill the buttocks, each have each skill", I give you a √.
In some writings, the use of Show (butcher) is called Pure polymorphism .
The method Show (butcher) is invoked as a subclass object reference, which is characterized by the method body. For the same kill () message. Because the message recipient B points to a different object . And there are different manifestations. 】
Polymorphism is a feature that cannot be applied independently, in fact. It is the upward styling and method of rewriting/override after a common effect. Some phenomena that appear when the program executes. In other words, the program code does not directly "write" polymorphic, just when the program executes, said: "Ah, I see polymorphic."
So. From a programming skill or source point of view:
★ Polymorphic = Up Styling + method rewriting (programming Tips).
】
★ polymorphic = polymorphic variable + dynamic binding (System mechanism)"p79"
Introduction to Programming (Java) & #183; 2.1.2, I see polymorphism.-What is polymorphic (polymorphism)