let me give a try for you. 
 
Let's say you've got a car object and a wheel object.  They both have methods called rotateTire(). 
 
When you call carobj.rotateTire(), something akin to the real world would happen.  After the method call, certain attributes of a given tire embedded in that car object would be different.  Maybe tire object 1 which used to be in the front is now in the back and the pressure has changed (like your car service should do for most cars (some run with equal front/rear) if you went there).  When you call tireobj.rotateTire(), you find after the call that the valve which used to be in the six o'clock position is now in the 12 o'clock position.
 
Caution:  the following is further rambling on related topics, but not directly to your question
 
Contrast with override and overload.  Override says that I will implement rotateTire() in the Chevy class because I need to do something extra or a little different than the Car class does with rotateTire (maybe Car.rotateTire just moved them and Chevy changes the tire pressure too).   Much discussion/argument centers around this but I think most programmers now agree that it is really bad form to radically change the meaning of rotateTire because that makes the contract pretty confusing.  Overload says that you have many rotateTire methods in your class.  I think the most use of this comes from accepting different inputs such as setBirthDate taking a Date, Timestamp, String, etc. 
 
My polymorphic example was a bit contrived by my reckoning all though lots of people disagree.  It is a naming question.  I would not name the method in Tire, rotateTire, but just rotate.  I try to name the action with a single verb when it applies to the object and verb/object when it doesn't (like rotateTire for the Car object).  I also do the same in database naming and class attribute naming.  Therefore I would name an internal database id for a Person, ID.  But in an Employee, I would name the foreign ID PersonID and the internal database id for Employee ID.  I would name the respective attributes in my class similarly.
 
 
 
 
-----Original Message-----
From: Santosh Varma [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 30, 2002 2:35 AM
To: JDJList
Subject: [jdjlist] OOPS -> Polymorphism

Hello all,
 
     Could any body of you explain me with an example what is meant by Polymorphism.....I went through many sites,,but it is bit confusing and not clear...

Thanks and regards,

Santosh

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to