About Question enthuware.ocpjp.v21.2.3096 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
giginar
Posts: 21
Joined: Fri Feb 07, 2025 5:36 pm
Contact:

About Question enthuware.ocpjp.v21.2.3096 :

Post by giginar »

3 - public <T> ArrayList<T> transform(List<T> list) {     return new ArrayList<T>(); };

that works fine.but why these are not working?

1 - public ArrayList<Number> transform(List<Number> list) {     return new ArrayList<Number>(); };
2 - public ArrayList<Object> transform(List<Object> list) {     return new ArrayList<Object>(); };

admin
Site Admin
Posts: 10433
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v21.2.3096 :

Post by admin »

Because the input parameter type in the base class's method is List<T>. What if the user of this method types it to some class XYZ?
In that case, the overriding method with List<Number> or List<Objective> will not be compatible with the base class's version.

Post Reply

Who is online

Users browsing this forum: No registered users and 146 guests