Skip to content
Sharp

Language Upgrades interview questions

Migration Strategy, Pattern Matching, Sealed Classes

67 questions with answers and explanations · 67 flashcards

Questions (page 2 of 2)

  1. 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
  2. What is required for a class to implement a sealed interface?Multiple choiceEasy
  3. Why do teams use sealed classes in Java in production code?Multiple choiceEasy
  4. 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
  5. What role does the 'permits' clause play in a sealed class declaration?Multiple choiceMedium
  6. What happens if a subclass of a sealed class is not declared as final, sealed, or non-sealed?Multiple choiceHard
  7. In the context of sealed classes, what does it mean for a subclass to be marked as 'non-sealed'?Multiple choiceHard
  8. How does pattern matching in switch expressions improve code safety?Multiple choiceMedium
  9. Which of the following is a primary benefit of using sealed classes in Java?Multiple choiceEasy
  10. Which of the following is NOT a valid way to define a class that extends a sealed class?Multiple choiceMedium
  11. In Java, what is one advantage of using sealed interfaces?Multiple choiceEasy
  12. How do sealed classes enhance domain modeling rules?Multiple choiceMedium
  13. How does the 'sealed' keyword in Java differ from 'final'?Multiple choiceMedium
  14. In an e-commerce system, a sealed class 'Order' allows only 'OnlineOrder' and 'InStoreOrder' as subclasses. What architectural benefit does this provide?Multiple choiceHard
  15. Why is a sealed hierarchy a good fit for PaymentResult with only Success, Failure, and Pending states?Multiple choiceMedium
  16. Which of the following is a valid use of a switch expression with pattern matching?Multiple choiceMedium
  17. Which of the following statements about sealed classes is true?Multiple choiceMedium