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?
About Question enthuware.ocpjp.v17.2.3688 :
Moderator: admin
-
- Posts: 13
- Joined: Wed Sep 28, 2022 9:41 am
- Contact:
-
- Site Admin
- Posts: 9804
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v17.2.3688 :
Did you try go through the complete explanation, specially point 4? It explains exactly why it 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.
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.
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 2 guests