Solved

Example of Polymorphis

Posted on 2006-06-11
3
234 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:martinez1112
  • 2
3 Comments
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 300 total points
ID: 16883179
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
0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 300 total points
ID: 16883185
0
 
LVL 8

Accepted Solution

by:
colr__ earned 200 total points
ID: 16883696
An example is the constructor of the Date class. It has the following variants:

Date()
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).

colr__
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now