Homework 3
This commit is contained in:
parent
bf60a078d7
commit
0afc86ceeb
129 changed files with 3163 additions and 4316 deletions
|
@ -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