Hello guys, have a problem.
i need to create a new City object which contains the variable" residents " in it.
i have a method in the country class which calls : int getNumOfResidents();
and i have a method in the City class which calls : long getNumOfResidnets();
now, i want from my Country class, to call the getNumOfResidents() from my City class.
but i don't know how, because they have the same names.
how can i call it from the city class ( i can't change any of these method names)?
Why can't you change the method names? That sounds like a bit of bad design or a poorly‑thought‑out assignment.
Assuming your City and Country classes are distinct, and ignoring the fact that the population of Chin may cause an overflow error with an int in thirty years, why is there a problem?If you call such a call from inside the Country object, you would have some way to find the city. Maybe you have a List<City>Because you call the method on the object reference, there is no problem with disambiguation.
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad: