About Question enthuware.ocpjp.v21.2.3313 :

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

Moderator: admin

Post Reply
Vadim.Benke
Posts: 4
Joined: Wed Jan 01, 2025 10:53 am
Contact:

About Question enthuware.ocpjp.v21.2.3313 :

Post by Vadim.Benke »

Given the following declarations:

Code: Select all

List<? super Booby> bV = null;
List<? extends Tooby> tV = null;
the statement

Code: Select all

bV.add( tV.get(0) );
which is marked as a correct answer could actually only throw a null pointer exception.

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

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

Post by admin »

That's true but the question specifically says, "Which of the following statements will compile without any error?"

Vadim.Benke
Posts: 4
Joined: Wed Jan 01, 2025 10:53 am
Contact:

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

Post by Vadim.Benke »

Indeed, you are right, thank you for the clarification.
As a practicing software developer it's hard to deal with senseless program code, I mean that which perfectly compiles but unconditionally throws an exception...
I have to learn to concetracte more on wording.

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

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

Post by admin »

The purpose of this question is to test the reader on their understanding of generics and polymorphism. Generics are a compile time thing only. The rest of the code is just a prop.

Vadim.Benke
Posts: 4
Joined: Wed Jan 01, 2025 10:53 am
Contact:

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

Post by Vadim.Benke »

Yes of course. As I wrote already - I have to learn deeply the difference between "compile", "run without exception", "doing nothing", "fully useless" for the test. In the practice I operate only with "it works" and "it doesn't".
If the lists would be initialized like ... = new ArrayList<>(); I would be more thinking about an .add, but I just skiped both add methods on null pointers as ... yes making no sense. :-)
And needed even an extra pointing to the word "compile" after reading the explanation. :-))

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 18 guests