Hai all, I wrote one class and within that I wrote a inner class. If I make some of the variable in the inner class static the compiler is complaing that inner class should not contain static member. I am not able to understand why it should not be like that. Is there any body who can explain what is the exact meaning behind this. Thanx sudhakar
Joined: Jan 26, 2001
unless inner class is not static inner class you are not allowed to have static members in it. There is one thing you can do to have a member static is by making it final but remember it's not the same then because it's a constant.
sudhakar, The reason that constraint is placed on inner classes is this : Unless an inner class is specified as static (which means it always exists), a non-static inner class needs an instance of the outer class to exist... Static attributes always exist, so how could a static attribute always exist if the class containing it ( the non-static inner class ) does not exist because it has no outer class to contain it? HTH, -Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Sep 29, 2000
y, Please change your name to be compliant with JavaRanch's naming policy. Your ID should be 2 separate names with more than 1 letter each. We really want this to be a proffesional forum and would prefer that you use your REAL name. Thanks, Cindy
"JavaRanch, where the deer and the Certified play" - David O'Meara