There are 5 characters in a computer game.
A Bunny IS-A Animal.
A Bird IS-A Animal.
A Frog IS-A Animal.
A Crocodile IS-A Animal.
A Hare IS-A Animal.
The game designers have decided that all Animals can speak. One of the advantages of Inheritance is that only the superclass needs to be modified.
The new Animal superclass design is .
And so, in a Main program we can now do this:
Bunny bunny = new Bunny("Bugs");
bunny.speak();
So all Animals speak.
But unfortunately they don't all say the same thing when they speak!
For example, when a Crocodile speaks, it says I am a wily Crocodile!
How can we handle this issue in OOP?
Open your IDE and complete the Worksheet.
Method overriding is different from Method overloading.
Method overloading means that within one class, more than one method with the same name can exist as long as the parameter list is the same.
Method overriding means that a subclass can override a sperclass's method. The name of the method and the parameter list MUST be the same!
Click the exercises button and see if you can complete the challenges.
object
property
method
create an object/instance of a class
instantiate an object
encapsulate
access
mutate
abstraction
methodsyntax overriding overloading instantiate instance super parameterattribute