What is the answer?
Polymorphism and dynamic binding (4 points total; 1 point each part)
Consider the following three classes:
public class Gee {
public String first() {
return "fee";
}
public String second() {
return "fi";
}
}
public class Tee extends Yee {
public String first() {
return "fo";
}
}
public class Yee extends Gee {
public String second() {
return "fum" + first();
}
public String third() {
return "from";
}
}
Assume that you have the following variable declarations, all of which are valid:
Gee g = new Yee();
Yee y1 = new Yee();
Yee y2 = new Tee();
Tee t = new Tee();
Consider the following statements. If a given statement would compile, state the output that it would produce when it is executed. If a given statement would not compile, explain why.
1. System.out.println(g.first() + " " + g.second() + " " + g.third()); // this statement is not valid because the method third() is undefined for the type Gee
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments