class Person{
public String name
; // インスタンス変数 public int money; // インスタンス変数
public void work(){ // インスタンスメソッド
money += 1000;
}
public void greet(){ // インスタンスメソッド
System.
out.
println("Hello, I am "+name
); }
public void eat(){ // インスタンスメソッド
money -= 500;
}
}
class Hoge{
public static void main
(String[] args
){ Person taro, jiro, saburo;
taro = new Person();
taro.name = "太郎";
taro.money = 500;
jiro = new Person();
jiro.name = "次郎";
jiro.money = 200;
saburo = new Person();
saburo.name = "三郎";
saburo.money = 50;
taro.greet();
System.
out.
println("太郎の所持金は"+taro.
money); taro.work();
System.
out.
println("太郎の所持金は"+taro.
money); jiro.greet(); // taro.greet()と異なる実行結果
}
}
Y2xhc3MgUGVyc29uewoJcHVibGljIFN0cmluZyBuYW1lOwkJLy8g44Kk44Oz44K544K/44Oz44K55aSJ5pWwCglwdWJsaWMgaW50IG1vbmV5OwkJLy8g44Kk44Oz44K544K/44Oz44K55aSJ5pWwCglwdWJsaWMgdm9pZCB3b3JrKCl7CQkvLyDjgqTjg7Pjgrnjgr/jg7Pjgrnjg6Hjgr3jg4Pjg4kKCQltb25leSArPSAxMDAwOwoJfQoJcHVibGljIHZvaWQgZ3JlZXQoKXsJCS8vIOOCpOODs+OCueOCv+ODs+OCueODoeOCveODg+ODiQoJCVN5c3RlbS5vdXQucHJpbnRsbigiSGVsbG8sIEkgYW0gIituYW1lKTsKCX0KCXB1YmxpYyB2b2lkIGVhdCgpewkJLy8g44Kk44Oz44K544K/44Oz44K544Oh44K944OD44OJCgkJU3lzdGVtLm91dC5wcmludGxuKCLjgYbjgb7jgYQhIik7CgkJbW9uZXkgLT0gNTAwOwoJfQp9CmNsYXNzIEhvZ2V7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKXsKICAgICAgICBQZXJzb24gdGFybywgamlybywgc2FidXJvOwogICAgICAgIHRhcm8gPSBuZXcgUGVyc29uKCk7CiAgICAgICAgdGFyby5uYW1lID0gIuWkqumDjiI7CiAgICAgICAgdGFyby5tb25leSA9IDUwMDsKICAgICAgICBqaXJvID0gbmV3IFBlcnNvbigpOwogICAgICAgIGppcm8ubmFtZSA9ICLmrKHpg44iOwogICAgICAgIGppcm8ubW9uZXkgPSAyMDA7CiAgICAgICAgc2FidXJvID0gbmV3IFBlcnNvbigpOwogICAgICAgIHNhYnVyby5uYW1lID0gIuS4iemDjiI7CiAgICAgICAgc2FidXJvLm1vbmV5ID0gNTA7CgogICAgICAgIHRhcm8uZ3JlZXQoKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIuWkqumDjuOBruaJgOaMgemHkeOBryIrdGFyby5tb25leSk7CiAgICAgICAgdGFyby53b3JrKCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCLlpKrpg47jga7miYDmjIHph5Hjga8iK3Rhcm8ubW9uZXkpOwogICAgICAgIGppcm8uZ3JlZXQoKTsgICAgICAgIC8vIHRhcm8uZ3JlZXQoKeOBqOeVsOOBquOCi+Wun+ihjOe1kOaenAogICAgfQp9Cg==