• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Polymorphism in java

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic