lec 14 writing an instantiable class iii. agenda review of instantiable classes scope of variables...

8
Lec 14 Writing an Instantiable Class III

Upload: meghan-leonard

Post on 21-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

Lec 14 Writing an Instantiable Class III

Page 2: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

Agenda

• Review of Instantiable Classes• Scope of variables• Using this to override scope issues • Lab: Creating a Car class for a video game

Page 3: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

Recall Structure of an Instantiable Class

class Balloon

sizecolor

BallooninflategetSizegetColorsetColorpop

Class NameInstance Varbls

Methods

Constructor methodsame name as class

Page 4: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

Structure of an Instantiable Dog Class

class Dog

size

DoggetSizesetSizebark

Class NameInstance Varbls

Methods

Constructor methodsame name as class

Page 5: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

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

Page 6: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

Scope errors in code below

Page 7: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

Memory Map

Dog fido = new Dog(30);

Page 8: Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables Using this to override scope issues Lab: Creating a

Lab14 You write a Car Class

class Car

double speed;int turnRate;

CargetSpeedgetTurnRateaccelerateturnMoreLeftturnMoreRight

Class NameInstance Varbls

Methods

Constructor methodsame name as class