• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Polymorphism

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would you explain Compile time and Runtime polymorphism? And also can someone explain me about dynamic dispatch?
[ April 11, 2007: Message edited by: Rick Charles ]
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Polymorphism:
Definition of Richard G. Baldwin (His Introductory Java Programming Tutorial will get you started):
compile-time polymorphism: method overloading
runtime polymorphism: method overriding and inheritance

Dynamic dispatch is explained in wikipedia.

Regards, Jan
[ April 11, 2007: Message edited by: Jan Cumps ]
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds more like a beginner's question to me.

I thought polymorphism was only seen at runtime. You will find lots of examples. Imagine you have a superclass, and you have subclasses; they can have methods which have the same signature (overridden) which use different operations. Example:-At compile time all the compiler will notice is that each of these three concrete classes extends Shape, and has a getArea() method. Also that the return types are compatible (in this case all the same, double).
Now, at runtime, you can create different subclasses of Shape:Your compiler can't tell whether you will enter 1 for Circle or 2 for Square or 3 for Triangle. But each has a getArea() method which the JVM finds and uses at Runtime.

try it
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic