Yes, if you use T1.VALUE, there is no ambiguity. The ambiguity arises when you try to use tc.VALUE. The given solution illustrates how to disambiguate the member that you want to use.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
That is correct. You cannot have non-final static fields in an interface. All fields are implicitly public, static, and final even if you don't declare them so.
-Paul.
If you like our products and services, please help us by posting your review here.
VALUE is not used in TestClass. So unless VALUE is used, there should be nothing wrong in the code. So, second option "There is nothing wrong with the code" can also be correct.
Let me know your comments.
I respect the Java Overlords, but talk about ambiguous test questions.
The question asks what is wrong with the code.
Answer is - nothing wrong with the code.
Explanation - technically something wrong with the code.
It's not like this is good practice to write code like this either. ZOMG. RIP. #SADBOYZ
admin wrote:Even though m1 is declared in two interfaces, their signatures are same. So both the interfaces are satisfied with the same implementation.
So, its ok to declare two methods with exactly the same signatures (with exact same params as well)?
And is it just in two interfaces or could we do this in two different classes(subclasses) as well? And can we call this an override?
Yes, in the given situation, it is ok. In other situations, such as in the same class or same interface, it is not ok. In a class/subclass, it is called overriding. You need to try it out.
If you like our products and services, please help us by posting your review here.