1

Possible Duplicate:
Why does Java prohibit static fields in inner classes?

I am getting very confused with the access specifications of inner classes. Please explain to me about private and protected inner classes and nested classes. I want to know why non-static members cannot be declared in static inner class.

Thanks alot.

Sorry... I was wrong. I want to know why static members can not be declared in nonstatic inner classes.. I asked in reverse way.. Sorry

Community
  • 1
  • 1
ranganath111
  • 457
  • 2
  • 7
  • 17

2 Answers2

0

Hopefully this answers some of your questions?

http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

But you are wrong, you can declare nonstatic members in a static nested class, the class being declared as static here is done to differentiate it from an inner class. Static nested classes can be instantiated like any other top level class, they are just refereed to in a static way:

new StaticClass.NestedClass()
Link19
  • 586
  • 1
  • 18
  • 47
0

Non-static members can for sure be declared in a static inner class, but not the other way is not allowed. See: Why does Java prohibit static fields in inner classes?

Community
  • 1
  • 1
Tobias Ritzau
  • 3,327
  • 2
  • 18
  • 29