This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Polymorphism in java  RSS feed

 
Greenhorn
Posts: 25
  • 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.
 
Ranch Hand
Posts: 1953
  • 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
  • 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
 
"The Hood"
Posts: 8521
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!