ITK 168 Lecture 5 - Inheritance

Preview:

DESCRIPTION

ITK 168 Lecture 5 - Inheritance. Examples. Review ExperimentRobot Lamp example. Overriding methods. Overriding occurs when a subclass implements a method of the same name as the superclass causing a change in behavior. Override example. Spinner robot Does 360 spin before turning left - PowerPoint PPT Presentation

Citation preview

ITK 168 Lecture 5 - Inheritance

Examples

• Review ExperimentRobot

• Lamp example

Overriding methods

• Overriding occurs when a subclass implements a method of the same name as the superclass causing a change in behavior

Override example

• Spinner robot– Does 360 spin before turning left

• Bad robot– Turns right when supposed to turn left– Turns left when supposed to turn right

Method Resolution

Robot

void move()

void turnLeft()RobotSE

void turnAround()

void turnRight() BadRobot

void turnLeft()

void turnRight()

Overriding with side effects

• Speedy