Question: (java) (object oriented) Consider the following definitions: void m(Object o, long x, long y) // defn 1 void m(String s, int x, long y) //

(java) (object oriented)

  1. Consider the following definitions:

void m(Object o, long x, long y) // defn 1

void m(String s, int x, long y) // defn 2

void m(Object o, int x, long y) // defn 3

void m(String s, long x, int y) // defn 4

and suppose you have the following variable declarations:

Object u;

String v;

int a;

long b;

For each of the following calls, determine which definitions would match a particular call; also decide whether the call is legal, and if so, which of the preceding definitions is selected:

m(v, a, b)

m(v, a, a)

m(v, b, a)

m(v, b, b)

m(u, b, b)

m(u, a, a)

Note that this question asks for three things. For a given invocation statement, such as m(v, a, b), the first question asks you to find all those overloaded methods that match the invocation. As long as an overloaded method can be invoked through implicit type casting, it is a match. Therefore, there could be several matching methods for an invocation statement. The second question asks you to identify whether the invocation is legal or not. If there is more than one most-specific matching method, a compiling error will occur and the invocation is considered illegal. Otherwise, you are asked to give the most-specific overloaded method among those matching methods.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!