Homework 3
This commit is contained in:
parent
bf60a078d7
commit
0afc86ceeb
129 changed files with 3163 additions and 4316 deletions
21
javali_tests/HW3_nop90/FieldTests/ErrorAccessField.javali
Normal file
21
javali_tests/HW3_nop90/FieldTests/ErrorAccessField.javali
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Test 'NO SUCH FIELD'
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C1 c1;
|
||||
C2 c2;
|
||||
c1 = new C1();
|
||||
c2 = new C2();
|
||||
c1.a = 5;
|
||||
c2.b = 6;
|
||||
}
|
||||
}
|
||||
|
||||
class C1{
|
||||
int a;
|
||||
}
|
||||
|
||||
class C2 extends C1 {}
|
||||
|
||||
class C3 extends C2 {}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// Access a field from an array (error, not a class type). Not even the length field exists
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int[] c;
|
||||
c = new int[10];
|
||||
write(c.length);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
// Error: access a field from a non-class type (primitive type int)
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int a;
|
||||
write(a.end);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
// access a field from a class and a superclass (also includes hidden fields)
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C1 c1;
|
||||
C2 c2;
|
||||
C4 c4;
|
||||
c1 = new C1();
|
||||
c2 = new C2();
|
||||
c4 = new C4();
|
||||
c1.a = 5;
|
||||
c2.a = 6;
|
||||
c4.a = false;
|
||||
}
|
||||
}
|
||||
|
||||
class C1{
|
||||
int a;
|
||||
}
|
||||
|
||||
class C2 extends C1 {}
|
||||
|
||||
class C3 extends C2 {}
|
||||
|
||||
class C4 extends C3 {
|
||||
boolean a;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue