About Question enthuware.ocpjp.v17.2.3689
Posted: Sat Nov 05, 2022 7:41 am
This question:
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.
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{
}
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.