回答編集履歴
1
追記
answer
CHANGED
@@ -1,1 +1,38 @@
|
|
1
|
-
`methodName(args)`は、`this.methodName(args)`と同じ意味です。
|
1
|
+
`methodName(args)`は、`this.methodName(args)`と同じ意味です。
|
2
|
+
|
3
|
+
実験
|
4
|
+
---
|
5
|
+
```Java
|
6
|
+
class MyClass {
|
7
|
+
void print(String str) {
|
8
|
+
System.out.println("called: " + str);
|
9
|
+
}
|
10
|
+
|
11
|
+
void func() {
|
12
|
+
this.print("this.print()");
|
13
|
+
print("print()");
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
class Main {
|
18
|
+
Main() {
|
19
|
+
// print(); もちろんここからは呼べない
|
20
|
+
}
|
21
|
+
|
22
|
+
public static void main(String[] args) {
|
23
|
+
MyClass mc = new MyClass();
|
24
|
+
|
25
|
+
mc.print("インスタンス名.print()");
|
26
|
+
mc.func();
|
27
|
+
|
28
|
+
new Main();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/kwFbF8GbrXmBFENJ)
|
34
|
+
```
|
35
|
+
called: インスタンス名.print()
|
36
|
+
called: this.print()
|
37
|
+
called: print()
|
38
|
+
```
|