Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables...
-
Upload
meghan-leonard -
Category
Documents
-
view
212 -
download
0
Transcript of Lec 14 Writing an Instantiable Class III. Agenda Review of Instantiable Classes Scope of variables...
![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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/1.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/2.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/3.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/4.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/5.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/6.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/7.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022083010/5697bfad1a28abf838c9c3df/html5/thumbnails/8.jpg)
Lab14 You write a Car Class
class Car
double speed;int turnRate;
CargetSpeedgetTurnRateaccelerateturnMoreLeftturnMoreRight
Class NameInstance Varbls
Methods
Constructor methodsame name as class