• 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

Compile-time polymorphism?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is java supports compile-time polymorphysm? how?
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Java Ranch. Use appropriate subject line, so it is easy to understand subject.

Yes Java supports compile time polymorphism. It is also called as method overloading. Method overloading means you are using same method name with different argument list.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

There is no such thing as compile-time polymorphism.

At least I don't think there is. I think polymorphism means you can call methods on objects of different types, and the methods behave as in the target. For examplebehaves according to the type of myFoo. That depends on the type of the object called. You get whatever myFoo has as its toString() method. Even if you declared myFoo to be of type Object, you get the overridden version of toString().
Overloading is different. . . all call the out object, which is actually a PrintStream. You are getting different methods called, but all on the same object (therefore all on the same type of object). So the difference does not depend on the "target" object; it depends on the calling method, passing an int, a long, a double, a BigInteger, and a BigDecimal in turn. So, if "polymorphism" means different behaviour depending on the called object, then overloading isn't polymorphism. Overloading depends on the type of argument passed by the calling method.
Click on the word polymorphism where it is underlined, and you get some more useful information
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Please UseAMeaningfulSubjectLine. What does "Harinath-mca" mean?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java, polymorphism generally refers to overridden methods being evoked based on runtime type of an object. This is sometimes called runtime polymorphism (or dynamic polymorphism). Note that this behavior is rooted in the object-oriented concept of subtyping.

Some people refer to method overloading as compile-time polymorphism (or static polymorphism) -- but there are plenty of arguments (no pun intended) against using this term.
reply
    Bookmark Topic Watch Topic
  • New Topic