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(){ |
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 Main{ | |
2 public static void main(String[] args){ | |
3 MuscleBoy mb1 = new MuscleBoy(); | |
4 mb1.hp = 100; | |
5 MuscleBoy mb2 = new MuscleBoy(); | |
6 mb2.hp = 70; | |
7 } | |
8 } |
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 Main{ | |
2 public static void main(String[] args){ | |
3 MuscleBoy mb = new MuscleBoy(); //インスタンスを生成 | |
4 mb.name = "ホエイ"; //初期値セット | |
5 mb.hp = 100; //初期値セット | |
6 MuscleGirl mg = new MuscleGirl(); //またインスタンスを生成 | |
7 mg.name = "アミノ"; //また初期値 | |
8 mg.hp = 100; //また初期値 | |
9 Protein p = new Protein(); //インスタンスを生成 | |
10 p.name = "プロテイン"; //初期値 |
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 Main { | |
2 public static void main(String[] args) { | |
3 Muscle m = new Muscle(); | |
4 m.name = "腹筋"; | |
5 System.out.println(m.name); | |
6 } | |
7 } | |
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
メソッドの定義 | |
public static 戻り値の型 メソッド名(引数){ | |
メソッドが呼び出された時に実行される処理 | |
} |
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 MuscleWorld{ | |
2 public static void main(String[] args){ | |
3 int[] number = {10,20,30,40,50}; | |
4 for(int i = 0; i < number.length; i++){ | |
5 System.out.println(number[i]); | |
6 } | |
7 } | |
8} |
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
【代表的な算術演算子】 | |
+ 足し算 2 + 8 =10 | |
- 引き算 10 - 2 = 8 | |
* 掛け算 2 x 5 = 10 | |
/ 割り算 3.2 / 2 →1.6 9/2 → 4 | |
% 割り算のあまり 9 % 2 → 1 |
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 HelloWorld{ | |
2 public static void main(String[] args){ | |
3 System.out.println("MuscleWorld!"); | |
4 } | |
5} |