Before our article on the Java Packaging and inheritance, encapsulation, and did not reflect the strength of the package, but also carefully use encapsulation. Because the package is not yet associated with polymorphism, there is no way to see the upside of the transformation.
Polymorphism means that the same behavior has many forms of expression. The same method produces various results depending on the calling object. For Java, polymorphism is the reference variable defined in the program, and the code that invokes the method is determined at compile time, but the object that the reference variable points to is determined at run time. To give a very simple example, one has to work. Work here is a method, but a writer's job is to write an article, a programmer's job is to write code. The work of the performer is different, the content of the work is different. This is a polymorphic.
Multi-State implementation
For us, the implementation of polymorphism should be prepared as follows.
- Inherited
- Method overwrite
- Upward transformation
For Java, it is implemented by dynamic binding. Let's take a look at what dynamic binding is, so that you can easily use polymorphic features later.
Dynamic binding
Binding refers to associating a method call with the same method body.
Dynamic binding is the value at run time according to the type of object binding, and the corresponding is static binding, binding at compile time, in Java only the final static private and the construction method is statically bound.
We already know that the invocation of a generic method is called at run time based on the type of the object, in other words, no matter what you write in the code, at run time it really determines which object is calling the method.
One of the three main features of Java: polymorphism