fork(1) download
  1. // Player0.java (または同じファイル内での定義)
  2. class Player0 {
  3. public int hp;
  4. public int place;
  5.  
  6. public void initi() {
  7. hp = 100;
  8. place = 0;
  9. }
  10.  
  11. public void work() {
  12. hp -= 1;
  13. place += 1;
  14. }
  15.  
  16. public void print() {
  17. System.out.println("hp: " + hp + ", place: " + place);
  18. }
  19. }
  20.  
  21. // Game0.java
  22. class Game0 {
  23. public static void main(String[] args) {
  24. // Player0型のインスタンス p を作る
  25. Player0 p = new Player0();
  26.  
  27. // hp と place を初期設定
  28. p.initi();
  29.  
  30. // hp と place を表示
  31. p.print();
  32.  
  33. // hp と place を更新
  34. p.work();
  35.  
  36. // 更新された hp と place を表示
  37. p.print();
  38. }
  39. }
Success #stdin #stdout 0.13s 55576KB
stdin
Standard input is empty
stdout
hp: 100, place: 0
hp: 99, place: 1