Forums Register Login

Same variable from two implemented interfaces

+Pie Number of slices to send: Send
If we call System.out.println(count); then erroe message shows like "The field is ambiguous.
Why two count variable separately present here which can be access through there respective interfaces.Why not one interface count variable hide another interface's count variable.Please explain internally what happens?

Thanks
Abhra
+Pie Number of slices to send: Send
A variable declared in an interface is always implicitly static.
Therefore AA.count and BB.count are different variables independent on each other.
By the way, what would you expect to print with System.out.println(count)?
+Pie Number of slices to send: Send
I thought as BB interface implemented last so it's count variable hide AA's count variable and always print 20
+Pie Number of slices to send: Send
The order of interfaces listet does not matter.
+Pie Number of slices to send: Send
Okk
Thanks a lot Pawel
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 338 times.
Similar Threads
Showing error of having same method in a class and an interface in implementing class
Member object talks back to parent object
inner-class inheritance & ambiguity
Map Problem
inheritance and class casting question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:40:12.