compiler-design-eth/javali_tests/HW4/OkVirtualMethod.javali
Carlos Galindo 72cc3206c4
Homework 4
2020-01-15 22:34:57 +01:00

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();
}
}