All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.
but referring to such fields/methods in an ambiguous way will cause a compile time error.
How can a method in interface, i.e here m1() be called in ambiguous way? Can you please provide an example. I know calling a field would as its implicitly static.
I don't think there can be any ambiguity in resolving methods in this case, at least in Java 7. In Java 8, you can have static methods in an interface as well.
But there are cases when a method can be called ambiguously. For example:
Please correct me if I am wrong, This example doesn't make the point ambiguity related to method call of an interface where 2 interfaces have same method name, and both are implemented by a class, this is just a sample of ambiguity related to calling method with a parameter, here method call is with the argument int, which wont fit into either short or byte, this can happen even we have any superclass which has these 2 methods, or one of the method is in super and another in sub, or both the methods are in same class.
I don't think there can be any ambiguity in resolving methods in this case, at least in Java 7. In Java 8, you can have static methods in an interface as well.
If you like our products and services, please help us by posting your review here.
I thought interfaces are "implement[ed]", but in this example interface T3 "extends" T1 and T2. How does that not make the answer E - "None of the above"?
Interfaces are implemented by classes. But they can also be extended by other interfaces. Option E cannot be correct because the given code compiles fine and so option 2 is correct.
If you like our products and services, please help us by posting your review here.
so why is "There is nothing wrong with the code" not the correct answer?
doesn't 'something being wrong' indicate that the code won't compile or work, rather than it not following best practice (marking methods public in an interface), or unnecessary method declarations in T3.
T3.m1() is also fine because even though m1() is declared in T2 as well as T3 , the definition to both resolves unambiguously to only one m1(). Explicit cast is not required for calling the method m1() : ( ( T2) t).m1();
T3.m1() cannot be fine since m1() is not a static method so it cannot be called in staitic way. Or I don't see the point here?