About Question enthuware.ocajp.i.v8.2.1203 :

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

Moderator: admin

Post Reply
Elnur_Aliyev
Posts: 1
Joined: Wed Jan 20, 2021 11:48 am
Contact:

About Question enthuware.ocajp.i.v8.2.1203 :

Post by Elnur_Aliyev »

I think "in the same package" should be added in this question, as it is not valid if superclass and subclass are in different packages.

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

Re: About Question enthuware.ocajp.i.v8.2.1203 :

Post by admin »

It would not be invalid even if the classes are in different package because a subclass can still have a method with the same signature. But it would not be overriding because the base class's method would not be visible in the subclass.

Chackingnoob
Posts: 1
Joined: Mon Jan 02, 2023 7:07 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1203 :

Post by Chackingnoob »

But then the question "A method with no access modifier defined in a class can be overridden by a method marked protected (assuming that it is not final) in the sub class."
is defined wrong.
Like you said, it will no longer be overridden.
Either the question should state that the super- and subclass are in the same package and then the answer is true
or the question doesn't specify and then the answer is false because it won't be true for every case.

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

Re: About Question enthuware.ocajp.i.v8.2.1203 :

Post by admin »

The problem statement is:
A method with no access modifier defined in a class can be overridden by a method marked protected (assuming that it is not final) in the sub class.
The question is clearly about the role of access modifiers while overriding a method. And it is correct to say that a method with no access modifier can be overridden by a method marked protected because protected is more accessible than no access modifier. Hence the statement is true. So I don't understand what is the issue.

Of course, it does not mean that a method m1() can be overridden by a method m2() even though that is not specified in the question either, right? It is clear from the context of the question that we are talking about the same method m1 and m1 (not m1 and m2)! Similarly, the issue of packages is irrelevant here. It has no bearing on the rule about access modifiers.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests