• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Example of Polymorphis

For the Class "Date" give examples of Polymorphis.  I can not find one example I will like to know if some one can send me to the right place.  Thanks
  • 2
3 Solutions
Mayank SAssociate Director - Product EngineeringCommented:
Polymorphism basically refers to existence in more than one form. Method overloading, etc are all implementations of polymorphism, e.g.,

public class MyClass
  public void someMethod ( String a )
  public void someMethod ( int i )

MyClass obj = new MyClass () ;
obj.someMethod ( "Hi" ) ; // calls the first method
obj.someMethod ( 1 ) ; // calls the second method
An example is the constructor of the Date class. It has the following variants:

Date(int year, int month, int date)
Date(int year, int month, int date, int hrs, int min)

... plus several more constructors.

Accorign to wikipedia:

In object-oriented programming theory, polymorphism is the ability of objects belonging to different types to respond to methods of the same name, each one according to the right type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, so this behavior can be implemented at run time (this is called late binding or dynamic binding).

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now