Skip to content

Instantly share code, notes, and snippets.

@amippy
Last active April 17, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amippy/03503521ad65a3ab9794a10d38a2e761 to your computer and use it in GitHub Desktop.
Save amippy/03503521ad65a3ab9794a10d38a2e761 to your computer and use it in GitHub Desktop.
筋トレ大好きな文系女学生のJava入門_カプセル化の目的&メリット ref: http://qiita.com/amippy/items/6d2f56881801d1521a8c
//アクセス制御されないプログラム
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 }
1 public class Protein{
2 void recover(MuscleBoy mb){
3 mb.hp -= 100; //不具合
4 }
5 }
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