About Question enthuware.ocajp.i.v7.2.1113 :
Moderator: admin
-
- Posts: 33
- Joined: Mon May 06, 2013 9:41 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1113 :
Perhaps if the question was put in the form of "Select the best option", it could be detailed why the chosen answer regarding covariant types should be considered "better" than plain Object (for me it is quite much context dependent what to use, so I do not consider this a very good phrasing, but maybe there are similar questions in the real exam as well?)
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1113 :
The problem statement does say, "(Select the best option.)".
-
- Posts: 13
- Joined: Mon Jun 16, 2014 1:07 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1113 :
After reading the explanation, I agree with the answer. However, I think "Select the best option" is subjective. Wouldn't both String and Object be technically valid answers? Would what is considered the "best option" be based on the purpose of the code being written?
As far as reinforcing the concept this question is trying to teach, would it make more sense if it allowed selection of multiple answers? Perhaps including primitives in the choices would help to clarify the point that covariance doesn't apply to them.
As far as reinforcing the concept this question is trying to teach, would it make more sense if it allowed selection of multiple answers? Perhaps including primitives in the choices would help to clarify the point that covariance doesn't apply to them.
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1113 :
Yes, they are valid options. However, there will be situations in the exam where multiple valid options may be present but you have to pick only one. So you have to select the option that is most suitable.
You are right about primitives. The explanation has been enhanced to explain that as well.
Paul.
You are right about primitives. The explanation has been enhanced to explain that as well.
Paul.
-
- Posts: 167
- Joined: Sun Apr 21, 2024 10:43 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1113 :
i hope i wont have Oracle error by saying: Return type can be any class since all objects can be cast to Object.
because imagine Oracle says you are wrong it cannot be anytype such as primitive
because imagine Oracle says you are wrong it cannot be anytype such as primitive
-
- Posts: 1
- Joined: Thu Aug 29, 2024 3:58 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1113 :
In the context of an exam or coding best practices, covariant types are often considered "better" than using Object because they offer a balance of flexibility and safety. However, the "best" option always depends on the specific use case and the context in which the code is being written.bptoth wrote: ↑Wed May 21, 2014 8:31 amPerhaps if the question was put in the form of "Select the best option",best sex dolls it could be detailed why the chosen answer regarding covariant types should be considered "better" than plain Object (for me it is quite much context dependent what to use, so I do not consider this a very good phrasing, but maybe there are similar questions in the real exam as well?)
-
- Posts: 8
- Joined: Wed Jan 08, 2025 9:43 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1113 :
There is a question:
However, your answer is fundamentally wrong for the reason that when overriding a method, it IS POSSIBLE to change the type of the return value. Therefore, the return value cannot be any type of object.
Here is the proof:
The answer that you think is correct is the following:Which of the following is a legal return type of a method overriding the given method:
public Object myMethod() {...}
(Select the best option.)
The question clearly states that we should override the method first and then give the answer.Return type can be any class since all objects can be cast to Object.
However, your answer is fundamentally wrong for the reason that when overriding a method, it IS POSSIBLE to change the type of the return value. Therefore, the return value cannot be any type of object.
Here is the proof:
Code: Select all
public interface Parent {
public Object myMethod();
}
Code: Select all
public class Main implements Parent {
@Override
public Long myMethod() {
return Integer.getInteger("1"); // Not compiler!
}
}
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1113 :
Well, the problem statement is asking about the return type of the method. It is not talking about the type of the value or of the variable that is actually returned by the method!
Who is online
Users browsing this forum: nkaragulov and 10 guests