Polymorphism
This presentation is the property of its rightful owner.
Sponsored Links
1 / 5

Polymorphism PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on
  • Presentation posted in: General

Polymorphism. Head First Java Page 183-188. Polymorphism. Direct result of inheritance - the subclasses inherit the methods that the superclass have. You define a common protocol for a set of classes related through inheritance You’re announcing the rules to any other code.

Download Presentation

Polymorphism

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Polymorphism

Polymorphism

Head First Java

Page 183-188


Polymorphism1

Polymorphism

  • Direct result of inheritance - the subclasses inherit the methods that the superclass have.

  • You define a common protocol for a set of classes related through inheritance

  • You’re announcing the rules to any other code.

  • If you extend me, if you’re a sub-type of me, you can do these things with these methods.


Polymorphism2

Polymorphism

  • When you create a superclass for a grouping of classes, any sub-class can be substituted where the super type is expected.????

  • Page 184 - Look at how an object is created

  • Reference variable; create object; link the object & the reference. Object type and reference type are the same

  • With polymorphism, the reference and the object can be different


Page 186

Page 186

  • With polymorphism, the reference type can be a superclass of the actual object type.

  • Declare an array of animals – the SuperClass

  • Because dog, cat, hippo, etc. are extended from Animal, in the array called animal, you can have objects called dog, cat, hippo, etc.

  • You can loop through the array, and call one of the methods, and every object does the right thing


Polymorphism

  • When you create a superclass for a grouping of classes, any sub-class can be substituted where the super type is expected

  • Look at Vet class, page 187

  • You can have polymorphic arguments and return types

  • READ page 188 – SUPER imoprtant!!!


  • Login