Given the following code, find the compile error.
```
public class Test {
public static void main(String[] args) {
m(new GraduateStudent());
m(new Student());
m(new Person());
m(new Object());
}
public static void m(Student x) {
System.out.println(x.toString());
}
}
class GraduateStudent extends Student {
}
class Student extends Person {
@Override
public String toString() {
return "Student";
}
}
class Person extends Object {
@Override
public String toString() {
return "Person";
}
}
}
a. m(new GraduateStudent()) causes an error
b. m(new Student()) causes an error
c. m(new Person()) causes an error
d. m(new Object()) causes an error
c. m(new Person()) causes an error
d. m(new Object()) causes an error
You cannot pass a supertype variable to a subtype without explicit casting.
You might also like to view...
Which virus type attaches itself to a file, usually an executable file?
A. Parasitic B. Stealth C. Polymorphic D. Macro
Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion.
a. a heap b. storage area c. a stack d. an array