Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Example of Polymorphis

Posted on 2006-06-11
3
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 1200 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 1200 total points
ID: 16883185
0
 
LVL 8

Accepted Solution

by:
colr__ earned 800 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

722 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