File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism in java

 
Manoj Chandran
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Zhang
Ranch Hand
Posts: 1953
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you're willing to read something:
Inheritance, polymorphism, static/dynamic binding, etc.
a lot of Q&As, examples, explanations, code, etc.
[This message has been edited by Roseanne Zhang (edited January 26, 2001).]
 
Manoj Chandran
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roseanna,I'll refer the site you suggested and try to get my doubts cleared.
Manoj
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic