About Question enthuware.ocpjp.v17.2.3689

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

Moderator: admin

Post Reply
theujior
Posts: 12
Joined: Fri Sep 09, 2022 8:41 am
Contact:

About Question enthuware.ocpjp.v17.2.3689

Post by theujior »

This question:

Code: Select all

//in file A.java
package p1;
sealed class A permits B{
}

//in file B.java
package p2;
final class B extends A{
}
and 1st option, which is correct answer:
The code will compile fine if both A and B are part of the same named module.
All permitted subtypes of a sealed type must either belong to the same package or to the same module.


Appropriate import statements are required.

OR,

1st option of enthuware.ocpjp.v17.2.3684 explains:
All permitted subclasses of a sealed class must belong to the same package (or belong to the same named module).
Since no module information is given in the problem statement, you should assume that there is no module in play here.


This question gives no module information too.
and 2nd option is:
Both the classes must belong to the same package for the code to compile.

2nd option is not incorrect.

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

Re: About Question enthuware.ocpjp.v17.2.3689

Post by admin »

It is true that no module information is given In this question. However, option 1 explicitly says that the code will compile fine if both A and B are part of the same named module. So, this option is indeed correct. Because it is valid ONLY IF they were in the same module. The option itself makes it clear and specifies the condition when it is valid.

In the other question, there is no module information and no "if" condition. That is why you cannot assume the presence of a module. It is making a blanket unconditional statement, which is incorrect.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 41 guests