50 lines
535 B
Text
50 lines
535 B
Text
/* Test virtual method calls */
|
|
class A {
|
|
void override() {
|
|
write(0);
|
|
writeln();
|
|
}
|
|
void base() {
|
|
write(1);
|
|
writeln();
|
|
}
|
|
}
|
|
|
|
class B extends A {
|
|
void override() {
|
|
write(2);
|
|
writeln();
|
|
}
|
|
void sub() {
|
|
write(3);
|
|
writeln();
|
|
}
|
|
}
|
|
|
|
class Main {
|
|
void main() {
|
|
A a;
|
|
B b;
|
|
|
|
a = null;
|
|
b = null;
|
|
|
|
a = new A();
|
|
a.base();
|
|
a.override();
|
|
|
|
b = new B();
|
|
b.base();
|
|
b.override();
|
|
b.sub();
|
|
|
|
a = b;
|
|
a.base();
|
|
a.override();
|
|
|
|
b.base();
|
|
b.override();
|
|
b.sub();
|
|
|
|
}
|
|
}
|