Homework 3

This commit is contained in:
Carlos Galindo 2020-01-15 22:32:25 +01:00
parent bf60a078d7
commit 0afc86ceeb
Signed by: kauron
GPG key ID: 83E68706DEE119A3
129 changed files with 3163 additions and 4316 deletions

View file

@ -0,0 +1,9 @@
// Test that you cannot invoke a method on an integer.
class Main {
void main() {
int x;
x = 1;
x.foo();
}
}

View file

@ -0,0 +1,9 @@
/* Test that the circular inheritance between Foo and Bar is detected */
class Foo extends Bar { }
class Bar extends Foo { }
class Main {
void main() {
writeln();
}
}

View file

@ -0,0 +1,11 @@
/* Test that if conditions must be boolean */
class Main {
void main() {
if (84 / 2) {
write(1);
writeln();
}
write(2);
writeln();
}
}

View file

@ -0,0 +1,14 @@
/* Test that an invalid field name is detected */
class X {
int field;
}
class Main {
void main() {
X x;
x = new X();
x.field = 0;
x.notafield = 1; /* ILLEGAL: bad field name */
}
}

View file

@ -0,0 +1,30 @@
/* Test that fields are inherited */
class A {
int foo;
}
class B extends A {
int bar;
}
class Main {
void main() {
A a;
B b;
a = new A();
a.foo = 1;
write(a.foo);
a = new B();
a.foo = 2;
write(a.foo);
b = new B();
b.foo = 3;
b.bar = 4;
write(b.foo);
write(b.bar);
}
}