90 likes | 250 Views
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.
E N D
EncapsulationInheritancePolyMorhpism 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 • 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
UML • Create UML diagram showing inheritance hierarchy
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
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
Key vocabulary • encapsulation, inheritance, polymorphism • class, superclass, subclass, extends • inheritance hierarchy (cf containment hierarchy) • override