JAVA Test class Test int no double score




簡単JAVA説明⑮ // Testクラスのクラス class Test{ int no; double score; void show(){ System. out. println("Noは" + no); System. out. println("点数は" + score); } }
![簡単JAVA説明⑮ // Testクラスのインスタンス作成 class Sample 1{ public static void main(String args[]){ Test test1 = 簡単JAVA説明⑮ // Testクラスのインスタンス作成 class Sample 1{ public static void main(String args[]){ Test test1 =](http://slidetodoc.com/presentation_image_h2/add34ebffa76fa74e538561be44e41c5/image-5.jpg)
簡単JAVA説明⑮ // Testクラスのインスタンス作成 class Sample 1{ public static void main(String args[]){ Test test1 = new Test(); test1. no = 1; test1. score = 85; test1. show(); Test test 2 = new Test(); test 2. no = 2; test 2. score = 75; test 2. show(); } }




簡単JAVA説明⑮ // Testクラスのクラス class Test{ public static int sum = 0; private int no; private double score; public Test() { no = 0; score = 0. 0; sum++; System. out. println("Noは" + no); } void show(){ System. out. println("Noは" + no); System. out. println("点数は" + score); }

簡単JAVA説明⑮ 5.privateとpubblic メンバへのアクセスの制限 class Test { int no; double score; void show() { System. out. println("Noは" + test. no); System. out. println("点数は" + test. score); } }
![簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test = 簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test =](http://slidetodoc.com/presentation_image_h2/add34ebffa76fa74e538561be44e41c5/image-11.jpg)
簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test = new Test(); test. no = 1; test. score = 85; test. show(); } } 上記のプログラムではテストNoと点数scoreに値を代入してい ます。


簡単JAVA説明⑮ class Test { private int no; private double score; void show() { System. out. println("Noは" + test. no); System. out. println("点数は" + test. score); } }
![簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test = 簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test =](http://slidetodoc.com/presentation_image_h2/add34ebffa76fa74e538561be44e41c5/image-14.jpg)
簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test = new Test(); test. no = 1; test. score = 85; test. show(); } }


簡単JAVA説明⑮ publicメンバの作成 privateメンバですと、クラスの外からアクセスできませ んが、 publicメンバとした場合、外からのアクセス が可能となります。 class Test { public int no; public double score; void show() { System. out. println("Noは" + this. no); System. out. println("点数は" + this. score); } }
![簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test = 簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test =](http://slidetodoc.com/presentation_image_h2/add34ebffa76fa74e538561be44e41c5/image-17.jpg)
簡単JAVA説明⑮ // Testクラスのオブジェクト作成 class Sample 1{ public static void main(String args[]){ Test test = new Test(); test. no = 1; test. score = 85; test. show(); } }


簡単JAVA説明⑮ 演習1.①~⑥を埋めよ。 class Person { String my. Name; int my. Age; public void Set. Name(String name) { my. Name = name; } public String Get. Name() { return my. Name; } public void Set. Age(int age) { my. Age = age; } public int Get. Age() { return my. Age; } }


簡単JAVA説明⑮ 実行結果 Tanaka 26 Suzuki 32

- Slides: 22