What is Polymorphism in Java? literally, polymorphism means many forms. Different living being may have the same behaviors, but react differently according to their own. A lion and a bird are both living beings, but they eat in different manners.
Just like in a real life, Java provides a mechanism to model this phenomena, and implemented by an way of method overriding in an inheritance hierarchy. this also incur the run-time method selection of object type refer to the reference variable type.
The tricky part maybe here, a reference variable could be declared as its base class or implemented interfaces, however its instantiated instances could have different forms modeled by its sub-classes. I think, this is also a kind of so called polymorphism. Declaring in a generic form, a super type, but it could be implemented by different concrete sub-types.
However, a critical concept of the polymorphism is about the method overriding. Super-class's instance methods can be inherited by the child classes, but where they can be overridden. So, for a super-class form, it not only could have different forms of run-time objects, but also their same methods can have different forms.
As overriding happens, invoking a method via a reference variable types, it needs to watch out which instance method has been pointed to. This depends on reference variable's run-time object.
Please note: an overridden method, just like its literal meaning, in the sub-class scope its super-class one has been destroyed. On this case, even for the super-class, it have to invoke its sub-class overridden one.
Subscribe to:
Post Comments (Atom)
Can Jackson Deserialize Java Time ZonedDateTime
Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...
-
Could not extract response: no suitable HttpMessageConverter found for response type [class dk.enettet.evu.core.model.Address] and content ...
-
First time met this hibernate exception. I think this issue should due to one to one relationship. One driver has one car; one car has on...
-
A large object refers to the entity property that is modified by @Lob. It may be persisted in several records. However, in database manage...
No comments:
Post a Comment