Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 201

Given:

and

public class Bar extends Foo { ... }

Which two statements are true if the method is added to Bar? (Choose two.)

    Correct Answer: B, E

    In the given context, adding a method to `Bar` that differs from `foo` in its argument types would result in method overloading, while changing the return type to a subtype of `Collection<T>` aligns it with method overriding rules in Java. Specifically, defining `public <T> Collection<T> foo(Stream<T> arg) { ... }` in `Bar` would overload `Foo.foo` because it takes a different parameter type. Furthermore, defining `public <T> List<T> foo(Collection<T> arg) { ... }` in `Bar` would override `Foo.foo` since `List` is a subtype of `Collection`, constituting a covariant return type. Thus, the correct options are B and E.

Discussion
ASPushkinOptions: AE

answer : ABE The bytecode after compilation with type erasure contains only normal classes, interfaces and methods, ensuring that no new types are produced. public Collection foo(Collection arg) {...} A) correct B) correct different arguments so this overloads C) not correct Iterable is an interface so it is not a covariant type E) correct return type is a covariant to Collection F) not correct this is overrides see A

d7bb0b2

that is ok a : is override b : is overload e: is override (List is a subtype of Collection, rule of override )

d7bb0b2

3 are valid: A: overload B: overrride C: overload

d7bb0b2

B: is overload sorry