Page 1 of 1

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

Posted: Tue Dec 03, 2019 5:30 am
by girishankaran
Hai,
Any one please explain this one please?

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

Posted: Tue Dec 03, 2019 8:46 am
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.

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

Posted: Fri Dec 13, 2019 11:11 am
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?

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

Posted: Fri Dec 13, 2019 11:24 am
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!

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

Posted: Fri Dec 13, 2019 12:03 pm
by demetrio
Kindly, can you let me know when you fix the answer so I can update the mock?

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

Posted: Fri Dec 13, 2019 1:36 pm
by admin
Fixed already.

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

Posted: Thu Feb 20, 2020 12:26 pm
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.

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

Posted: Thu Feb 20, 2020 12:26 pm
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.

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

Posted: Thu Feb 20, 2020 12:39 pm
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.

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

Posted: Thu Feb 20, 2020 1:10 pm
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....

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

Posted: Fri Jun 12, 2020 5:32 pm
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.

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

Posted: Fri Jun 12, 2020 11:26 pm
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.

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

Posted: Sat Jun 13, 2020 9:36 am
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!

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

Posted: Sat Jun 13, 2020 9:43 am
by admin
Sure, your point is well taken. Will improve on the explanation.