質問編集履歴
1
「試したこと」に追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,8 +66,48 @@
|
|
66
66
|
|
67
67
|
### 試したこと
|
68
68
|
|
69
|
-
|
70
|
-
https://processing.org/reference/private.html
|
69
|
+
##### 1. Processingの公式リファレンス等を参照
|
70
|
+
・公式リファレンス:https://processing.org/reference/private.html
|
71
|
+
|
72
|
+
以下が公式リファレンスに記述してある内容です。
|
73
|
+
> This keyword is used to disallow other classes access to the fields and methods within a class. The private keyword is used before a field or method that you want to be available only within the class. In Processing, all fields and methods are public unless otherwise specified by the private keyword.
|
74
|
+
> This keyword is an essential part of Java programming and is not usually used with Processing. Consult a Java language reference or tutorial for more information.
|
75
|
+
|
76
|
+
この内容を見ると、privateキーワードを使用することで「クラスのメンバ変数について、他のクラスからアクセスできないようにする」ことができるように見受けられます。
|
77
|
+
|
78
|
+
##### 2. privateキーワード以外を指定
|
79
|
+
|
80
|
+
以下のように、privateキーワード以外を使用してプログラムを実行してみました。
|
81
|
+
しかし、事象は変わりませんでした(エラーがなく実行される)。
|
82
|
+
|
83
|
+
```Student.pde
|
84
|
+
class Student {
|
85
|
+
|
86
|
+
// メンバ変数
|
87
|
+
protected int studentNo; // 学生番号
|
88
|
+
protected String name; // 名前
|
89
|
+
|
90
|
+
// コンストラクタ
|
91
|
+
Student(int studentNo, String name) {
|
92
|
+
this.studentNo = studentNo;
|
93
|
+
this.name = name;
|
94
|
+
}
|
95
|
+
|
96
|
+
// メソッド
|
97
|
+
int getStudentNo() {
|
98
|
+
return this.studentNo;
|
99
|
+
}
|
100
|
+
String getName() {
|
101
|
+
return this.name;
|
102
|
+
}
|
103
|
+
void setStudentNo(int studentNo) {
|
104
|
+
this.studentNo = studentNo;
|
105
|
+
}
|
106
|
+
void setName(String name) {
|
107
|
+
this.name = name;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
```
|
71
111
|
|
72
112
|
### 補足情報(FW/ツールのバージョンなど)
|
73
113
|
|