Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following Java code: interface I { int f(); int g();} abstractclassCimplementsI{publicintf(){return3;}} class D extends C{ public int f() { return 7; } public

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?


Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programmers Guide To Java SE 8 Oracle Certified Associate OCA

Authors: Khalid Mughal, Rolf Rasmussen

1st Edition

0132930218, 978-0132930215

More Books

Students also viewed these Programming questions

Question

How can we separate myth from reality?

Answered: 1 week ago