Question
interface I { int f(); int g();} abstract class C implements I {public int f() {return 3;} } class D extends C { public int
interface I { int f(); int g();}
abstract class C implements I {public int f() {return 3;} }
class D extends C {
public int f() { return 7; }
public int g() { return f() + 5 * super.f(); }
}
class E extends D { public int f() {return 11;} }
class F extends E { public int f() {return f();} }
//... in some other class, perhaps in main()...
final I x = new D(); System.out.println(x.g());
final I y = new E(); System.out.println(y.g());
// a What does the code print? (the two system.out.println()'s)
// b What are the static (compile time) and dynamic (runtime) types of x? Static: Dynamic:
// c What are hte static and dynamic types of y? Static: Dynamic:
// d In the context of the code above, what happens when you evaluate the expression new F().f() (this is legitimate "method chaining")? If there is any problem, what causes it?
// e Why must class C be declared as abstract? (implements one interface, does not implement all the methods in interface, does not have any instance variables, does not have a superclass)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started