Skip to content

Instantly share code, notes, and snippets.

@benhlal
Created August 24, 2021 18:16
Show Gist options
  • Select an option

  • Save benhlal/c637a5d7fe97400f12463af5ce6932be to your computer and use it in GitHub Desktop.

Select an option

Save benhlal/c637a5d7fe97400f12463af5ce6932be to your computer and use it in GitHub Desktop.
Sealed Class to restrict inheritance
public abstract sealed class Animal
permits Cat,Dog {....}
//
public class Cat extends Animal{...} //Complies fine
public class Dog extends Animal{...} //Complies fine
public class Lion extends Animal{...}//Compiler will complain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment