Consider the following Java code: interface I { int f(); int g();} abstractclassCimplementsI{publicintf(){return3;}} class D extends C{
Question:
Consider the following Java code:
interface I { int f(); int g();}
abstractclassCimplementsI{publicintf(){return3;}} 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; } } classFextendsE{publicintf(){returnf();}}
//... 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. 1What does this code print? (the twoSystem.out.println()'s)
b. 1 What are the static (compile-time) and dynamic (runtime) types ofx?Static: Dynamic:
c. 1 What are the static and dynamic types ofy?Static: Dynamic:
d. 1In the context of the code above, what happens when you evaluate theexpression
new F().f() (this is legitimate "method chaining")? If there is any problem, what causes it?
Programmers Guide To Java SE 8 Oracle Certified Associate OCA
ISBN: 9780132930215
1st Edition
Authors: Khalid Mughal, Rolf Rasmussen