Lec 14 Writing an Instantiable Class III
Agenda
• Review of Instantiable Classes• Scope of variables• Using this to override scope issues • Lab: Creating a Car class for a video game
Recall Structure of an Instantiable Class
class Balloon
sizecolor
BallooninflategetSizegetColorsetColorpop
Class NameInstance Varbls
Methods
Constructor methodsame name as class
Structure of an Instantiable Dog Class
class Dog
size
DoggetSizesetSizebark
Class NameInstance Varbls
Methods
Constructor methodsame name as class
Now we'll begin ScopeThisDog Demo
• create Dog and MainApp classes• show how scope errors can cause compile
failure• scope of
– instance variables, parameters, and local variables• Using keyword this to resolve scope issues
in Class definition files
Scope errors in code below
Memory Map
Dog fido = new Dog(30);
Lab14 You write a Car Class
class Car
double speed;int turnRate;
CargetSpeedgetTurnRateaccelerateturnMoreLeftturnMoreRight
Class NameInstance Varbls
Methods
Constructor methodsame name as class