About Question enthuware.ocajp.i.v7.2.1047 :

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

Moderator: admin

Post Reply
rbartolay
Posts: 2
Joined: Thu Feb 26, 2015 3:27 am
Contact:

About Question enthuware.ocajp.i.v7.2.1047 :

Post by rbartolay »

This would have been true prior to Java 1.5. But from Java 1.5, an overriding method is allowed to change the return type to any subclass of the original return type, also known as covariant return type. This does not apply to primitives, in which case, the return type of the overriding method must match exactly to the return type of the overridden method.
Whats the java version used in the actual exam?

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

Re: About Question enthuware.ocajp.i.v7.2.1047 :

Post by admin »

OCAJP 7 i.e. 1Z0-803 is based on Java SE 7.

Molinox
Posts: 1
Joined: Thu Jul 27, 2017 3:49 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1047 :

Post by Molinox »

I did understand this question yet, sorry.

For example.
class Base{
public void metodo() {
System.out.println("original");
}
}

public class Child extends Base {
@Override
public void metodo() {//If put here public int metodo, with return type int too, do will not work
System.out.println("changed");
}

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

Re: About Question enthuware.ocajp.i.v7.2.1047 :

Post by admin »

As the explanation says, this does not apply to primitives. You can change the return type in the overriding method to a subclass. int is not a subclass of void.
But if you change public List metodo() to public ArrayList metodo(), it will work.

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests