Created
August 24, 2021 18:16
-
-
Save benhlal/c637a5d7fe97400f12463af5ce6932be to your computer and use it in GitHub Desktop.
Sealed Class to restrict inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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