Member-only story
Java 17 Interview Practice Test: Hands-on
In this article, we will explore Java 17 Practice Test with hands-on. It incorporates Interview Questions & Answers with detailed explanation. The article covers all types of questions such as concept-based, code-based and scenario-based. Some of the questions are based on features of Java 21 as well. You will have both conceptual & practical knowledge of the topics after going through all the questions.
Q#1. What is the effect of the following code snippet in Java 17?
public sealed interface Animal permits Dog, Cat { }
public non-sealed class Dog implements Animal { }
public final class Cat implements Animal { }
A) Dog can have subclasses
B) Cat can have subclasses
C) Animal can have additional subclasses outside permits
D) Dog cannot have subclasses
Answer: A) Dog can have subclasses
Explanation:
- A): Correct. A non-sealed class allows further subclassing.
- B): Incorrect. final prevents subclassing for Cat.
- C): Incorrect. Animal can have subclasses inside permits only.
- D): Incorrect. Since Dog is a non-sealed class, it can have subclasses.