Homework 3
This commit is contained in:
parent
bf60a078d7
commit
0afc86ceeb
129 changed files with 3163 additions and 4316 deletions
|
@ -0,0 +1,17 @@
|
|||
// Test more complex/nested cases of CIRCULAR INHERITANCE
|
||||
|
||||
class Main {
|
||||
void main() {}
|
||||
}
|
||||
|
||||
class D1 extends C{}
|
||||
|
||||
class E extends D1{}
|
||||
|
||||
class D2 extends C{}
|
||||
|
||||
class E2 extends D2{}
|
||||
|
||||
class F extends E2{}
|
||||
|
||||
class C extends F{}
|
|
@ -0,0 +1,28 @@
|
|||
// Test long loops of circular inheritance
|
||||
|
||||
class A extends Z {}
|
||||
class B extends A {}
|
||||
class C extends B {}
|
||||
class D extends C {}
|
||||
class E extends D {}
|
||||
class F extends E {}
|
||||
class G extends F {}
|
||||
class H extends G {}
|
||||
class I extends H {}
|
||||
class J extends I {}
|
||||
class K extends J {}
|
||||
class L extends K {}
|
||||
class M extends L {}
|
||||
class N extends M {}
|
||||
class O extends N {}
|
||||
class P extends O {}
|
||||
class Q extends P {}
|
||||
class R extends Q {}
|
||||
class S extends R {}
|
||||
class T extends S {}
|
||||
class U extends T {}
|
||||
class V extends U {}
|
||||
class W extends V {}
|
||||
class X extends W {}
|
||||
class Y extends X {}
|
||||
class Z extends Y {}
|
|
@ -0,0 +1,5 @@
|
|||
// Test inheritance of itself
|
||||
|
||||
class Main extends Main {
|
||||
void main() {}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
// Simple circular inheritance loop
|
||||
|
||||
class Main extends Other {
|
||||
void main() {}
|
||||
}
|
||||
|
||||
class Other extends Main {}
|
|
@ -0,0 +1,10 @@
|
|||
// Inherited methods cannot be overloaded
|
||||
|
||||
class Main extends Other {
|
||||
void main() {}
|
||||
void method(int a) {}
|
||||
}
|
||||
|
||||
class Other {
|
||||
void method() {}
|
||||
}
|
30
javali_tests/HW3_nop90/InheritanceTests/OkAccessField.javali
Normal file
30
javali_tests/HW3_nop90/InheritanceTests/OkAccessField.javali
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Access inherited and hidden fields (general check)
|
||||
|
||||
class Other {
|
||||
int a;
|
||||
int b;
|
||||
Object c;
|
||||
Other o;
|
||||
}
|
||||
|
||||
class Main extends Other {
|
||||
int a, b;
|
||||
|
||||
void main() {
|
||||
Other o;
|
||||
o = (Other) this;
|
||||
a = 1;
|
||||
b = 2;
|
||||
o.a = -1;
|
||||
o.b = -2;
|
||||
write(a);
|
||||
write(b);
|
||||
write(o.a);
|
||||
write(o.b);
|
||||
if (c != null) {
|
||||
if (o.o != null) {
|
||||
write(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// call an method from a superclass
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C2 c;
|
||||
c = new C2();
|
||||
c.aux();
|
||||
}
|
||||
}
|
||||
|
||||
class C1{
|
||||
void aux(){
|
||||
write(2);
|
||||
}
|
||||
}
|
||||
|
||||
class C2 extends C1 {}
|
16
javali_tests/HW3_nop90/InheritanceTests/OkHideField.javali
Normal file
16
javali_tests/HW3_nop90/InheritanceTests/OkHideField.javali
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Hide a field from a superclass (type doesn't need to match)
|
||||
|
||||
class Parent {
|
||||
int a;
|
||||
}
|
||||
class Main extends Parent {
|
||||
Object a;
|
||||
Main b;
|
||||
void main() {
|
||||
Parent c;
|
||||
b = new Main();
|
||||
b.a = new Object();
|
||||
c = new Parent();
|
||||
c.a = 10;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// The number of parameters when overriding a method must be equal
|
||||
|
||||
class Other {
|
||||
void action() {
|
||||
write(10);
|
||||
}
|
||||
}
|
||||
|
||||
class Main extends Other {
|
||||
void action(int num) {
|
||||
write(num);
|
||||
return num + 1;
|
||||
}
|
||||
|
||||
void main() {}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// The return type when overriding a method must be equal
|
||||
|
||||
class Other {
|
||||
void action() {}
|
||||
}
|
||||
|
||||
class Main extends Other {
|
||||
int action() {
|
||||
write(10);
|
||||
return 8;
|
||||
}
|
||||
|
||||
void main() {}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
// The type of parameters when overriding a method must match the overridden method
|
||||
|
||||
class Other {
|
||||
void action(int num) {
|
||||
write(num);
|
||||
}
|
||||
}
|
||||
|
||||
class Main extends Other{
|
||||
void action(boolean name) {
|
||||
if (name) {
|
||||
writeln();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// Call method that has been overridden (both the new and old one)
|
||||
|
||||
class Other {
|
||||
void method() {}
|
||||
}
|
||||
|
||||
class Main extends Other {
|
||||
void main() {
|
||||
Other o;
|
||||
method();
|
||||
o = (Other) this;
|
||||
o.method();
|
||||
}
|
||||
|
||||
void method() {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue