1 / 8

Encapsulation Inheritance PolyMorhpism

Encapsulation Inheritance PolyMorhpism. Object-Oriented Programming Principles. Create New Project. OOPPrinciples. Animal Class. Fields: name dangerous Methods: toString () getters and setters says(), which returns a string of what noise the animal makes. Three Subclasses.

franz
Download Presentation

Encapsulation Inheritance PolyMorhpism

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EncapsulationInheritancePolyMorhpism Object-Oriented Programming Principles

  2. Create New Project • OOPPrinciples

  3. Animal Class • Fields: • name • dangerous • Methods: • toString() • getters and setters • says(), which returns a string of what noise the animal makes

  4. Three Subclasses • Dog, Cat, Sheep… • Whatever as long as you have three • Each should subclass Animal… class Dog extends Animal { } • Override the says() method for each new class

  5. UML • Create UML diagram showing inheritance hierarchy

  6. OOPPrinciples Main • Create a new empty Animal[] array of ten Animals • Populate it with random animals of the subclasses that you created, ie Dog, Cat, Sheep, etc (ie you should not know which animals are which) • Loop through the array and for each animal print the return value of the says method

  7. Notes • Make notes on which part of your code demonstrates • Encapsulation • Inheritance • Polymorphism • Write a concise definition for each • Write a short paragraph outlining the advantage(s) of each

  8. Key vocabulary • encapsulation, inheritance, polymorphism • class, superclass, subclass, extends • inheritance hierarchy (cf containment hierarchy) • override

More Related