Can we have a static class in Java?
I'll answer
Earn 20 gold coins for an accepted answer.20
Earn 20 gold coins for an accepted answer.
40more
40more
Studied at University of Oxford, Lives in Oxford, UK
But remember you can only declare a static class inside a top-level class, it is illegal to declare it inside an inner class. Nested classes (a class within a class) are the only ones that can be declared static. This is so the parent class does not have to be instantiated to access the nested class.
2023-05-15 14:10:00
评论(499)
Helpful(122)
Helpful
Helpful(2)

Noah Garcia
QuesHub.com delivers expert answers and knowledge to you.
But remember you can only declare a static class inside a top-level class, it is illegal to declare it inside an inner class. Nested classes (a class within a class) are the only ones that can be declared static. This is so the parent class does not have to be instantiated to access the nested class.