Sunday, October 2, 2022
HomeJavaQuiz your self: Creating information inside a Java sealed-type hierarchy

Quiz your self: Creating information inside a Java sealed-type hierarchy


Oracle Java, Java Career, Java Skills, Java Jobs, Java Tutorial and Material, Java Career, Java Certification, Java Prep, Java Preparation

A report kind is at all times implicitly last, so it can’t be prolonged by both a daily class or a report.

You’re designing an IoT system managed by Java. The system has two modes, one for day and one for night time. The modes differ when it comes to configuration information, and that information ought to be fixed, so you will have determined to make use of Java information for the implementation. Additional, since no different mode varieties are permitted, you will have determined to seal the mode hierarchy one thing like this, however haven’t determined what the kind of ought to be used to implement the mother or father of the sealed Mode hierarchy:

Learn Extra: 1Z0-829: Oracle Java SE 17 Developer

public sealed <kind> Mode permits DayModeRecord, NightModeRecord {

}

Which assertion is true? Select one.

A. The Mode kind should be a category.

B. The Mode kind should be a report.

C. The Mode kind should be an interface.

D. The Mode could also be both a category or an interface.

Reply. Typically, a sealed-type hierarchy can have a category or an interface as its root. The rest of the hierarchy can comprise courses or interfaces, supplied all leaf nodes of the hierarchy are both last concrete courses or are non-sealed.

If a leaf aspect is non-sealed, it may be both a category or an interface.

Nonetheless, a report is prohibited from utilizing an extends clause, as a result of all report varieties have java.lang.Document as their mother or father, and this can’t be made express. Consequently, a report can’t inherit from any user-selected class. Subsequently, making Mode a category would forestall the 2 mode information from inheriting from the bottom. From this, you understand that the Mode kind should not be a category; subsequently, possibility A and possibility D are incorrect.

Possibility B means that the Mode kind ought to be a report. Nonetheless, a report kind is at all times implicitly last, so it can’t be prolonged by both a daily class or a report. Due to this, possibility B should be incorrect.

You’ve seen that an interface is permitted for the foundation (and doubtlessly some additional components) in a sealed-type hierarchy, and though a report is prohibited from explicitly extending something, information are permitted to implement interfaces. Possibility C proposes making the Mode kind an interface, and it’s clearly not solely a sound strategy, however it’s the one legitimate approach to create a sealed-type hierarchy the place a leaf node within the sealed hierarchy is a report. From this, you’ll be able to see that possibility C is appropriate.

Conclusion. The right reply is possibility C.

Supply: oracle.com

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments