exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 3 discussion

Actual exam question from Oracle's 1z0-819
Question #: 3
Topic #: 1
[All 1z0-819 Questions]

Given:

and

Which two method definitions at line n1 in the Bar class compile? (Choose two.)

  • A. public List<Number> foo(Set<String> m) {...}
  • B. public List<Integer> foo(Set<CharSequence> m) {...}
  • C. public List<Integer> foo(TreeSet<String> m) {...}
  • D. public List<Object> foo(Set<CharSequence> m) {...}
  • E. public ArrayList<Integer> foo(Set<String> m) {...}
  • F. public ArrayList<Number> foo(Set<CharSequence> m) {...}
Show Suggested Answer Hide Answer
Suggested Answer: BC 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
curiouss
Highly Voted 1 year, 3 months ago
Selected Answer: BC
B ✅ -> overrides: Same method signature including return type C ✅ -> overloads: Same method signature including return type, overloads with a subclass as method parameter
upvoted 5 times
ASPushkin
2 months, 1 week ago
return part isn't taken into account for overloads
upvoted 1 times
...
...
ASPushkin
Most Recent 6 days, 20 hours ago
Selected Answer: BC
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
upvoted 1 times
...
ASPushkin
2 months, 1 week ago
Selected 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.
upvoted 1 times
...
james2033
1 year, 1 month ago
Selected Answer: BC
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.
upvoted 1 times
...
Omnisumem
1 year, 3 months ago
Selected Answer: BC
Tested: B and C.
upvoted 2 times
...
Lebannin
1 year, 4 months ago
Selected Answer: BC
the answer is B and C, B is overriding and C is overloading
upvoted 3 times
...
Stavok
1 year, 5 months ago
Selected Answer: BD
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.
upvoted 2 times
Lebannin
1 year, 4 months ago
D is not overloading, you cannot change the return type
upvoted 3 times
...
...
Mukes877
1 year, 6 months ago
F is not for returning Incompatible type and E is not for Name-Clash error in Set parameter. So correct answers is BC
upvoted 1 times
...
iCOW
1 year, 7 months ago
Selected Answer: BC
BC is correct not CF since F returning incompatible type.
upvoted 1 times
...
Ankit1010
1 year, 10 months ago
BC is correct
upvoted 1 times
...
UcefSoft
2 years ago
BC is correct
upvoted 2 times
...
deti27
2 years, 1 month ago
BC, not F, because returns "attempting to use incompatible return type"
upvoted 3 times
...
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago