Solved

Example of Polymorphis

Posted on 2006-06-11
3
239 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 60
Maven Project: Hibernate Dependencies Conflict 10 40
arguments to jar 5 35
IBM TS2900 (3572) Tape Autoloader Java? 12 19
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

820 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