B ✅ -> overrides: Same method signature including return type
C ✅ -> overloads: Same method signature including return type, overloads with a subclass as method parameter
subtype of List<Integer> is ArrayList<Integer>
so we can consider BCE
B is the same - overriding
C - different parameter list - overloading
E - should be same generics
answer: BC
answer: BC
A. not correct
there is a same erasure for method signature but different generics for the parameter variable. So there is no overriding.
B. correct
same signature method and the return part
C. correct
overloading
same method name but different parameter
D. not correct
same signature including parameter variable generic but incompatible return type (according to Liskov substitution principle)
E. is not correct
there is a same erasure for method signature but different generics for the parmeter variable. So there is no overriding.
F. not correct
same signature including parameter generic but incompatible return type (accotding to Liskov substitution principle) It will work for ArrayList<Integer> return type.
File Foo.java
import java.util.List;
import java.util.Set;
public class Foo {
public List<Integer> foo(Set<CharSequence> m) {
return null;
}
}
File Bar.java
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class Bar extends Foo {
// line n1. B
//public List<Integer> foo(Set<CharSequence> m) {
// return null;
//}
// line n1. C
public List<Integer> foo(TreeSet<String> m) {
return null;
}
}
Choose B, C.
This is a question about method overriding in Java. The method foo in the Bar class must have the same signature as the foo method in the Foo class to override it. This means that the return type and the parameter types must be the same. Therefore, the correct answers are B and D. Both of these options have a return type of List<Integer> and a parameter type of Set<CharSequence>, which matches the signature of the foo method in the Foo class.
BC, not F, because returns "attempting to use incompatible return type"
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
curiouss
Highly Voted 1 year, 3 months agoASPushkin
2 months, 1 week agoASPushkin
Most Recent 6 days, 20 hours agoASPushkin
2 months, 1 week agojames2033
1 year, 1 month agoOmnisumem
1 year, 3 months agoLebannin
1 year, 4 months agoStavok
1 year, 5 months agoLebannin
1 year, 4 months agoMukes877
1 year, 6 months agoiCOW
1 year, 7 months agoAnkit1010
1 year, 10 months agoUcefSoft
2 years agodeti27
2 years, 1 month ago