final class in java

A class that is declared with the final keyword is known as the final class. A final class can’t be inherited by subclasses. By use of the final class, we can restrict the inheritance of class. We can create a class as a final class only if it is complete in nature it means it must not be an abstract class. In java, all the wrapper classes are final class like String, Integer, etc.
If we try to inherit a final class, then the compiler throws an error at compilation time. We can’t create a class as immutable without the final class.
We can create a final class by use of final keyword during the declaration of the class. We just need to take the class should be complete. It should not an abstract class.
accessModifier final class className
{
    // Body of class
}
Here accessModifier specifies the scope of the method. You can read about access modifiers.
final is a keyword that is used to make a final method.
returnType is the type of data that you want to return from the method.
className is the name of class.

Posted on by