Language Upgrades interview questions
Migration Strategy, Pattern Matching, Sealed Classes
67 questions with answers and explanations · 67 flashcards
Questions (page 2 of 2)
- Given the following code, what would be the correct way to allow 'GiftCard' to extend 'Payment'? sealed class Payment permits CreditCard, PayPal {} final…Multiple choiceMedium
- What is required for a class to implement a sealed interface?Multiple choiceEasy
- Why do teams use sealed classes in Java in production code?Multiple choiceEasy
- Consider the following code snippet of a sealed class hierarchy. Which class is incorrectly defined given the sealed class rules? sealed class Payment permits…Multiple choiceMedium
- What role does the 'permits' clause play in a sealed class declaration?Multiple choiceMedium
- What happens if a subclass of a sealed class is not declared as final, sealed, or non-sealed?Multiple choiceHard
- In the context of sealed classes, what does it mean for a subclass to be marked as 'non-sealed'?Multiple choiceHard
- How does pattern matching in switch expressions improve code safety?Multiple choiceMedium
- Which of the following is a primary benefit of using sealed classes in Java?Multiple choiceEasy
- Which of the following is NOT a valid way to define a class that extends a sealed class?Multiple choiceMedium
- In Java, what is one advantage of using sealed interfaces?Multiple choiceEasy
- How do sealed classes enhance domain modeling rules?Multiple choiceMedium
- How does the 'sealed' keyword in Java differ from 'final'?Multiple choiceMedium
- In an e-commerce system, a sealed class 'Order' allows only 'OnlineOrder' and 'InStoreOrder' as subclasses. What architectural benefit does this provide?Multiple choiceHard
- Why is a sealed hierarchy a good fit for PaymentResult with only Success, Failure, and Pending states?Multiple choiceMedium
- Which of the following is a valid use of a switch expression with pattern matching?Multiple choiceMedium
- Which of the following statements about sealed classes is true?Multiple choiceMedium