Page 1 of 1

About Question enthuware.ocpjp.v17.2.3687 :

Posted: Tue Oct 08, 2024 6:31 pm
by fgomezt
Given the following code:

interface Readable{ } non-sealed class Device implements Readable { }

sealed class DocType implements Readable permits Book, Journal { }

final non-sealed class Book extends DocType{ }

final class Journal extends DocType{ }

Which types will fail compilation?


Book
Non-sealed implies that a class may have subclasses, while final implies that a class cannot be subclassed. Both are contradictory. That is why, a class cannot be both - final and non-sealed, at the same time.



Why is this answer correct?

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

Posted: Tue Oct 08, 2024 9:54 pm
by admin
Because it does fail compilation for the same reason as is given. Since the question asks which types will fail compilation, option 4, i.e. Book is a correct option.