Last active
April 17, 2016 14:29
-
-
Save amippy/03503521ad65a3ab9794a10d38a2e761 to your computer and use it in GitHub Desktop.
筋トレ大好きな文系女学生のJava入門_カプセル化の目的&メリット ref: http://qiita.com/amippy/items/6d2f56881801d1521a8c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//アクセス制御されないプログラム | |
1 public class MuscleBoy{ | |
2 int hp; | |
3 String name; | |
4 static int money; | |
5 | |
6 void run(){ | |
7 System.out.println(this.name + "は、逃げた!"); | |
8 } | |
9 void drink(){ | |
10 System.out.println(this.name + "は、飲んでいる"); | |
11 } | |
12 void workOut(){ | |
13 this.hp -= 10; | |
14 System.out.println(this.name + "は、筋トレをした!"); | |
15 System.out.println("−10ポイントHPが減った!!"); | |
16 } | |
17 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 public class Protein{ | |
2 void recover(MuscleBoy mb){ | |
3 mb.hp -= 100; //不具合 | |
4 } | |
5 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 public class SportsTrainer{ | |
2 void talk (MuscleBoy mb){ | |
3 System.out.println("おつかれさん!" + mb.name ); | |
4 System.out.println("今回の筋トレ疲れたじゃろ?"); | |
5 System.out.ptintln("プロテイン摂取して、回復しといてな〜。では、次回のトレで会おう!"); | |
6 mb.drunken(); //ここが不具合の原因!酔っ払ってしまった・・。 | |
7 } | |
8} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment