To add one note on this ( I agree the earlier
Cat / Dog example was educations ) - Bruce 
Eckel's book "Thinking in Java" has the best
explanation of Polymorphism / Overloading / 
Overriding I'v read.  He has a clarity and writing
style in this area that is truly unique.

http://www.mindview.net/Books/TIJ/

---------------------------------------
Considering the Certified Java Programmer Exam?
Get JCertify 5.0!
http://www.enterprisedeveloper.com/jcertify
The best investment in your career you will make all
year



--- David Rosenstrauch <[EMAIL PROTECTED]> wrote:
> At 12:05 PM 5/30/2002 +0530, you wrote:
> >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 
> 
> 
> 
> take a look at this:
> 
> 
> public class
> Animal {
>         public void makeNoise() {
>                 System.out.println("what am I
> supposed to say?");
>         }
> }
> 
> public class
> Dog extends Animal {
>         public void makeNoise() {
>                 System.out.println("woof");
>         }
> }
> 
> public class
> Cat extends Animal {
>         public void makeNoise() {
>                 System.out.println("meow");
>         }
> }
> 
> public class
> AnimalTest() {
>         public static void
>         main(String[]  args) {
>                 Animal
>                         a1 = new Dog(),
>                         a2 = new Cat();
>                 a1.makeNoise();
>                 a2.makeNoise();
>         }
> }
> 
> 
> The output, obviously is:
> 
> woof
> meow
> 
> This is polymorphism in action.
> 
> You have 2 Animal references (a1 & a2).  But the
> behavior of these objects depends not on the
> declared type of the references (Animal), but upon
> the actual type of the objects (Dog and Cat).
> 
> That's polymorphism.  So in a nutshell, polymorphism
> basically means that objects of the same
> interface/type exhibit different behavior depending
> on their actual subclass type.
> 
> HTH.
> 
> 
> DR
> 
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

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

Reply via email to