Felix Grund
Instructor @ UBC
Class | Cat |
Attribute / Field | name, age, weight |
Method | meow(3), sleep(), eat() |
Constructor | Create a new cat objects (e.g. Luna) |
Object / Instance | Luna (created by constructor) |
Class | Dog |
Attribute / Field | name, age, weight |
Method | bark(2), sleep(), eat() |
Constructor | Create new dog objects (e.g. Charlie) |
Object / Instance | Charlie (created by constructor) |
Class
Methods
Attributes/Fields
Constructor
1
2
3
4
(View > Tool Windows > Structure)
From: Space Invaders
Tank myTank;
myTank = new Tank(400);
myTank.faceLeft();
myTank.move();
Declare new variable myTank of type Tank
Assign new Tank object to variable
Call faceLeft method on Tank object
Call move method on Tank object
Tank myTank;
myTank = new Tank(400);
Tank object
direction 1
x 400
myTank
myTank
This does not create an object/instance yet, but only a (potential) reference to a tank
We first need to create an object
myTank.faceLeft();
myTank
Tank object
direction -1
x 400
myTank.move();
myTank
Tank object
direction -1
x 399
Tank
move
Tank
handleBoundary
Tank.move
GamePanel.drawMissiles
GamePanel.drawMissiles
GamePanel
drawMissiles
SIGame
getMissiles
GamePanel
drawMissile
Missile
getX
Missile
getY
Note: constructors are just methods in call graphs, e.g.
Person
Person
By Felix Grund