This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
hello, I want to know about how polymorphism is achieved in Java.Does method overloading enables polymorphism? Is the conventional polymorphism different from run-time poly...? Also plz differentiate between dynamic binding,run-time binding and dynamic method dispatch...Plz reply immediately.. Thanks in advance.. Manoj Chandran.
Roseanne's notes are really good reading. The not so sort version is: polymorphism = "many shape changes" This is achieved in Java using subclassing. A Base class can have many subclasses, each being a different variety of the Base class. So if I have a whole bunch of instances of the subclasses, I know that I can handle all of them the way I would handle a Base - CUZ they ARE Bases, just particular kinds of Bases. There is the famous Animal Class, with subClasses Cat, Dog, Horse, etc - but they are all animals, so they all have animal attributes like species, color, sex, etc. and they all have animal behaviors like eat(), move(), play() etc. Dynamic binding happens at run-time, static binding happens at compile time. This is especially important to understand when putting a subclass into a variable defined as the Base class. Since variables have static binding and methods use dynamic binding they will be handled differently. Base b = new SubClass(); When b is created the variables of Base are constructed and initialized the way a Base wants them. The system does not wait to see what will actually be in the variable at runtime. However when the SubClass is shoved into base, the methods (which are resolved at run-time) of the SubClass override the method behaviors of the Base.
"JavaRanch, where the deer and the Certified play" - David O'Meara