How do you make a class non inheritable?

To create a non heritable class in java declare the class as final using final keyword in front of class declaration . Final class cannot be inherited. To create a non overridable method decalre the method private or final. Both the keyword final and private avoid prevent a method from being overridden.

Sizin İçin Seçtik  What happens when you don't use super () constructor?

Leave a Reply

Your email address will not be published. Required fields are marked *