About Question enthuware.ocpjp.i.v11.2.3091 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
girishankaran
Posts: 10
Joined: Wed Aug 08, 2012 5:00 am
Contact:

About Question enthuware.ocpjp.i.v11.2.3091 :

Post by girishankaran »

Hai,
Any one please explain this one please?

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

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by admin »

Hello,
Can you tell me which part is not clear so that we can explain? You will need to read the module options summary given in the explanation. The options are very straight forward. No trick is involved in this question.

thank you,
Paul.
If you like our products and services, please help us by posting your review here.

demetrio
Posts: 16
Joined: Mon Sep 30, 2019 11:40 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by demetrio »

Is that sentence really correct: "first check whether the return type of the overriding method is a subtype. For example, if the overriding method returns List, the overridden method can return ArrayList but not Object." As far as I understand, ArrayList is a subType of List, right? That sad, I can have:

class Base{
public List getList(){ //overridden method
return null;
};
}

class Derived extends Base{
@Override
public ArrayList getList(){ //overriding method with subtype
return null;
}
}

Same question regard " List<? super Object> is a subtype of list<? super CharSequence>". In fact, CharSequence is a subType of Object instead, right?

Maybe I am messing up the terms overriding with overridden. As fas as I understand, overriding is the one replacing the method from Base, right?

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

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by admin »

>As fas as I understand, overriding is the one replacing the method from Base, right?
Yes. Overridden method is the method in base class, overriding method is the method in subclass.

You are right. That sentence should say: For example, if the overridden method returns List, the overriding method can return ArrayList but not Object.

thank you for your feedback!
If you like our products and services, please help us by posting your review here.

demetrio
Posts: 16
Joined: Mon Sep 30, 2019 11:40 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by demetrio »

Kindly, can you let me know when you fix the answer so I can update the mock?

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

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by admin »

Fixed already.
If you like our products and services, please help us by posting your review here.

Dani1515
Posts: 9
Joined: Mon Feb 17, 2020 12:10 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by Dani1515 »

public List<? super CharSequence> getList(int id){ return null;

i dont really know, why this question is on the mock exams for ocp java 11 part 1. The generics are not even listed in the official list of exam objectives. And this question needs even advanced knowledge of generics to answer it. I really hope that is a mock exams fault and I am not going to see suchs questions on the exam.

Dani1515
Posts: 9
Joined: Mon Feb 17, 2020 12:10 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by Dani1515 »

public List<? super CharSequence> getList(int id){ return null;

i dont really know, why this question is on the mock exams for ocp java 11 part 1. The generics are not even listed in the official list of exam objectives. And this question needs even advanced knowledge of generics to answer it. I really hope that is a mock exams fault and I am not going to see suchs questions on the exam.

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

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by admin »

You *are* going to see basic questions on generics on OCP 11 Part 1 exam. Even though they are not mentioned explicitly in the objectives, several people have reported getting such questions. Even our instructors got them. You should at least go through the basics discussed in OCP Java 11 Part 1 Fundamentals by Hanumant Deshmukh.
If you like our products and services, please help us by posting your review here.

Dani1515
Posts: 9
Joined: Mon Feb 17, 2020 12:10 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by Dani1515 »

thanks for answering, of course I did it through the mantioned book chapter (sub chapter of interfaces), but no chance to answer that question. I really dont know what they are at Oracle thinking/doing, not even mentioning generics but bring such a question to part 1 exams....

dimitrilc
Posts: 35
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by dimitrilc »

The explanation oversimplified too many concepts here. It should mention:

A. Difference between covariant and contravariant return types. The title of the explanation is "Rule of Covariant Returns", which is misleading. It is true that the compiler treats all legally overriding return types as "subtypes", but a return type with wild card generics includes both the "root" type (left side of <>) and the wildcard type (inside the <>); the upper-bounded wildcard will only accept a covariant return; the lower-bounded wildcard will only accept a contravariant return.

B. Clear distinction between the left side of the wildcard generics and the wildcard generics part itself. The 'root' type and the wildcard type, together, forms a new type. Test takers need to evaluate the root and the wild card type INDEPENDENTLY between the overridden and the overriding method.

C. Forgot to replace A with List in the examples.

D. When a root type is parameterized with a non range-bounded generic(generics that do not use wildcards), then the root type part is still covariant, but the "non range-bounded generic" is invariant.

E. Probably better examples.

These two articles explain these concepts well:
https://www.freecodecamp.org/news/under ... 4c19763d2/
https://dzone.com/articles/covariance-a ... ravariance

As a beginner, I did not even know the terms contravariant and invariant exist. Maybe add then to the book as well? The concept of Inheritance with generics/wild card generics won't stick unless these terms are understood. Once I understood all three terms covariant, contravariant, and invariant, this concept is as clear as daylight.

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

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by admin »

A. Not sure why you think the title is misleading because it accurately describes what the explanation is talking about. It is talking about the rule regarding covariant returns.

B. Yes, the details that you have provided are correct but the exam does not require that much detail. Hence, the simplification. It is already very difficult to present information that is not squarely within exam objectives. We have to provide justification for every tiny bit of information that seems to fall outside the exam objectives. Even so, we try to make sure that you are able to answer the questions without getting bogged down with details while still being technically correct. The two relations mentioned in the explanation are actually very correct and work in all situations.

C. You are right. Fixed.

D. Covariant and Rule of Covariant returns are two different things. We are talking about the rule for covariant return types for method overriding here.

E. Thanks for your suggestion. Will improve on that.

The terms covariant and covariant returns are mentioned in the book in section 9.2.3 page 192 and 12.4.2 page 286. Too many details are not really required for this exam. Just the general idea is enough.
If you like our products and services, please help us by posting your review here.

dimitrilc
Posts: 35
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by dimitrilc »

Thank you for your reply.

I simply stated that the concept of inheritance+generics was hard for me to understand, as a beginner, based on just the information provided in the explanation. I had to use other resources to be able to understand the concept. Maybe because you are an experienced programmer that the hierarchy formulas provided make perfect sense to you, but it's not easy for me, as a newbie, to grasp.

I already understand the concept, so there is really no motivation for me suggest any feedback here. But I saw 3 other students before me also had questions about this same question/concept, so I thought my opinion would maybe help them or future students as well.

Cheers!

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

Re: About Question enthuware.ocpjp.i.v11.2.3091 :

Post by admin »

Sure, your point is well taken. Will improve on the explanation.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests