18. // 人間クラス
class Human {
int hp;
int mp;
public Human(int hp, int mp) {
this.hp = hp;
this.mp = mp;
}
public work(int time) {
hp -= time * 10000;
}
}
// 適当なメソッド
public void foo() {
// ① 人間生成
Human yamada = new Human(65535, 1);
// ② 人間働く(24時間)
yamada.work(24);
// ③ メソッド終了
}
19. // 人間クラス
class Human {
int hp;
int mp;
public Human(int hp, int mp) {
this.hp = hp;
this.mp = mp;
}
public work(int time) {
hp -= time * 10000;
}
}
// 適当なメソッド
public void foo() {
// ① 人間生成
Human yamada = new Human(65535, 1);
// ② 人間働く(24時間)
yamada.work(24);
// ③ メソッド終了
}
スタックメモリ
変数
yamada
ヒープメモリ
① 人間生成
Humanオブジェクト
Hp : 65535
MP : 1
参照
20. // 人間クラス
class Human {
int hp;
int mp;
public Human(int hp, int mp) {
this.hp = hp;
this.mp = mp;
}
public work(int time) {
hp -= time * 10000;
}
}
// 適当なメソッド
public void foo() {
// ① 人間生成
Human yamada = new Human(65535, 1);
// ② 人間働く(24時間)
yamada.work(24);
// ③ メソッド終了
}
スタックメモリ
変数
yamada
ヒープメモリ
① 人間生成
Humanオブジェクト
Hp : 65535
MP : 1
参照
スタックメモリ
変数
yamada
ヒープメモリ
② 人間働く(24時間)
Humanオブジェクト
Hp : -174465
MP : 1
参照
21. // 人間クラス
class Human {
int hp;
int mp;
public Human(int hp, int mp) {
this.hp = hp;
this.mp = mp;
}
public work(int time) {
hp -= time * 10000;
}
}
// 適当なメソッド
public void foo() {
// ① 人間生成
Human yamada = new Human(65535, 1);
// ② 人間働く(24時間)
yamada.work(24);
// ③ メソッド終了
}
スタックメモリ
変数
yamada
ヒープメモリ
① 人間生成
Humanオブジェクト
Hp : 65535
MP : 1
参照
スタックメモリ
変数
yamada
ヒープメモリ
② 人間働く(24時間)
Humanオブジェクト
Hp : -174465
MP : 1
参照
スタックメモリ
変数
yamada
ヒープメモリ
③ メソッド終了
Humanオブジェクト
Hp : -174465
MP : 1
参照
22. // 人間クラス
class Human {
int hp;
int mp;
public Human(int hp, int mp) {
this.hp = hp;
this.mp = mp;
}
public work(int time) {
hp -= time * 10000;
}
}
// 適当なメソッド
public void foo() {
// ① 人間生成
Human yamada = new Human(65535, 1);
// ② 人間働く(24時間)
yamada.work(24);
// ③ メソッド終了
}
スタックメモリ
変数
yamada
ヒープメモリ
① 人間生成
Humanオブジェクト
Hp : 65535
MP : 1
参照
スタックメモリ
変数
yamada
ヒープメモリ
② 人間働く(24時間)
Humanオブジェクト
Hp : -174465
MP : 1
参照
スタックメモリ
変数
yamada
ヒープメモリ
③ メソッド終了
Humanオブジェクト
Hp : -174465
MP : 1
参照
出番やでー
参照が誰からもされていないので、
おばちゃん(GC)から「ごみ」と認識され、
掃除対象となる