Possible Duplicate:
Java: Static vs non static inner class
What is a static nested class?
What is the difference between static and non-static nested classes?
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.
A static inner class is a class nested inside another class that has the
staticmodifier. It’s pretty much identical to a top-level class, except it has access to the private members of the class it’s defined inside of.Class
Inner1is a static inner class. ClassInner2is an inner class that’s not static. The difference between the two is that instances of the non-static inner class are permanently attached to an instance ofOuter— you can’t create anInner2without anOuter. You can createInner1object independently, though.Code in
Outer,Inner1andInner2can all access x; no other code will be allowed to.