Solved

Example of Polymorphis

Posted on 2006-06-11
3
236 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:Mayank S
Mayank S 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:Mayank S
Mayank S 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sites similar to codingbat to improve coding hanson skills 3 40
mockito example issue 8 62
factorial example 4 34
fibonacci ten numbers 4 24
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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

919 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

19 Experts available now in Live!

Get 1:1 Help Now