Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference Between final class and static class

Tags:

java

I know a java a little bit , have used final and static multiple times , But I am quiet confused here : What is the basic difference between a final class A and a static class B. I know these keywords . Just could not imagine the use of final in a class declaration.

like image 772
Abhishek Bhandari Avatar asked Feb 16 '23 04:02

Abhishek Bhandari


1 Answers

Final class : In simple words is a class that cannot be extended . - It is generally useful for writing classes to be immutable e.g. String class that is generally done for security

Static class : Static classes can only be used in case of nested classes. - Nested static class doesn't need reference of Outer class but non static nested class needs it

like image 119
Harpreet Singh Avatar answered Feb 17 '23 20:02

Harpreet Singh