It correct to define an outer class as static which have inside also a static class? Only one instance of outer and inner classes is needed. Can outer class be abstract and it’s enclosed class be static?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, a top level class can’t be static. The meaning of “static” in a class declaration is only relevant to nested classes. You can certainly have a static nested class within an abstract class though.
From the JLS section 8.1.1:
Note that if you want “only one instance” of a class, you should potentially make it a singleton – which is entirely separate, and not something which affects the class declaration itself.