?
Solved

Polymorophism

Posted on 2003-03-30
9
Medium Priority
?
189 Views
Last Modified: 2010-03-31
Hi:
   Can someone show/explain how a static method can demonstrate polymorphism?  
0
Comment
Question by:LearningJava
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8235284
You can still extend static methods...

...is this an exam question?  

Hmmm...

I hear the EE police coming...
0
 

Accepted Solution

by:
purrbert earned 750 total points
ID: 8235444
Hi,

Say I've created a class with methods...

public class Customer {
   private String _name;
   private String _address;

   // method 1
   public void Delete(){
      ....}
   // method 2
   public boolean Delete(Customer ct) {
      ....}
}

Notice that within my class, I have 2 methods named "Delete".  How can I do that?  Polymorphism!
One method (2) will let you pass the Customer instance to it and perform some operation (denoted by the ....).  The other will Delete the "current" customer.
If you are familiar with other programming languages, the methods are like functions.  However, in other languages,
you can't have 2 functions that are named the same but will accept different input parameters.  Thus the power of Java.
If you are confused by the "current" customer comment, it refers to the keyword "this".  If that is confusing let me know.

Hope this helps!
Jill
0
 

Author Comment

by:LearningJava
ID: 8235463
No! This is not an exam question.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:TimYates
ID: 8235486
So your question was "What is Polymorphism?"
0
 

Expert Comment

by:purrbert
ID: 8235519
I didn't care if it was an exam question or not.
Tim, was my explanation appropriate?  I used "this".. even though I used in incorrectly in my own inquiry.
LearningJava, did you understand my explanation?
Jill
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8235531
Yeah, I had forgotten exactly what polymorphism was ;-)

hee hee...ignoe me, it's past my bed time >_<
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8235532
Bah...see what I mean >_<

ignoe==ignore
0
 

Author Comment

by:LearningJava
ID: 8235567
Yes, the explanation was adequate.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8237745
 You can find a nice explanation of polymorphism here: http://www.javaworld.com/javaworld/javatips/jw-javatip30.html as well. Also a nice article on parametric polymorphism (polymorphism obtained through parameters what purrbert explained essentially): http://www.javaworld.com/jw-02-2000/jw-02-jsr.html but you might find it a bit too advanced.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

621 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