質問編集履歴
1
説明文の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,6 +76,12 @@
|
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
+
###説明文
|
80
|
+
|
81
|
+
Notice that o2.myStaticMethod invokes Parent.myStaticMethod(). If this method were truly overridden,we should have invoked Child.myStaticMethod, but we didn't. Rather, when you invoke a static method, even if you invoke it on an instance, you really invoke the method associated with the "compile-time type" of the variable. In this case, the compile-time type of o2 is Parent. Therefore, we invoke Parent.myStaticMethod(). However, when we execute the line o2.myInstanceMethod(), we really invoke the method Child.myInstanceMethod(). That's because, unlike static methods, instance methods CAN be overridden. In such a case, we invoke the method associated with the run-time type of the object. Even though the compile time type of o2 is Parent, the run-time type (the type of the object o2 references) is Child. Therefore, we invoke Child.myInstanceMethod rather than Parent.myInstanceMethod().
|
82
|
+
|
83
|
+
|
84
|
+
|
79
85
|
### 質問
|
80
86
|
|
81
87
|
上記の説明に、★はcompile-time type を見ているから出力が”A"になると書いてあり、☆はrun-time type を見ているから”D"になると書いてあるのですが、このcompile-time type とrun-time typeの明確な違いがわかりません。これらの明確な違いを教えてください。
|