Page 1 of 1

About Question enthuware.ocpjp.v17.2.3688 :

Posted: Fri Jan 13, 2023 1:08 pm
by edufin166@yahoo.com
Why the option "Making the Book class extend Document will eliminate all compilation errors." is correct?

1 - "sealed class Document implements Readable permits Book{ " there is no problem here, the trouble come from "non-sealed class Book implements Readable { }" because this last one "no extends the sealed class THAT permits it.

Am I wrong?

Re: About Question enthuware.ocpjp.v17.2.3688 :

Posted: Fri Jan 13, 2023 1:35 pm
by admin
Did you try go through the complete explanation, specially point 4? It explains exactly why it is correct.
4. When you make Book extend Document, all compilation errors will be fixed because the issues explained in points 1 and 2 above will be resolved. There will be no issue with Journal because Book itself is not sealed (even though its parent, i.e. Document, is). It is ok for a class to indirectly extend a sealed class. Only direct subclasses of a sealed class have to be listed in the permits clause.


>1 - "sealed class Document implements Readable permits Book{ " there is no problem here, the trouble come from "non-sealed class Book implements Readable { }" because this last one "no extends the sealed class THAT permits it.

As of now, there indeed is a problem with the Document class. It "permits" a class (Book) which is not its subclass class. That is why it won't compile.