![]() ![]() Now where you may be thinking Abstraction and Polymorphism are similar might be in the case where you build your interface. In very simplified terms, Java knows that c is really an AutomaticTransmissionCar and so its drive() method is used. ![]() Which drive() method to use is determined at run-time based on the concrete type of the variable c. (ducks.toString() + Driver.BLANK_LINE) ĭrawing a Rubber Duck to use of an interface "Duck" around the types of ducks, allows a programmer to call a for loop in which they can call any method that is contained in the "Duck" interface. In order for polymorphism to work, the signatures must be exactly identical for all three of these. These methods are found in one common interface.įor example if we were working with different types of ducks, we could say that they all have common things that they do, but do them in slightly different ways. The different object react differently, yet share the same methods. Polymorphism means many forms or many shapes. This is the ability to work with objects that react differently in a more efficient manner. A variable of a superclass type can reference an object of a subclass type. So, polymorphism in Java is in a way to enable us to create a class in general, which becomes more specific as we extend it through sub-classification. ![]()
0 Comments
Leave a Reply. |