次の 3 つのクラスがあるとします。
class Foo {
void fn() {
System.out.println("fn in Foo");
}
}
class Mid extends Foo {
void fn() {
System.out.println("fn in Mid");
}
}
class Bar extends Mid {
void fn() {
System.out.println("fn in Bar");
}
void gn() {
Foo f = (Foo) this;
f.fn();
}
}
public class Trial {
public static void main(String[] args) throws Exception {
Bar b = new Bar();
b.gn();
}
}
を呼び出すことは可能Foo
ですfn()
か? が type のオブジェクトを指しているため、 のソリューションがgn()
機能しないことはわかっています。this
Bar