Download presentation
Presentation is loading. Please wait.
1
Encapsulation Inheritance PolyMorhpism
Object-Oriented Programming Principles
2
Create New Project OOPPrinciples
3
Animal Class Fields: Methods: name dangerous 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.