Hi, Accroding to Khalid Mugal, local inner classes (those defined inside a method body) can not have any access modifier defined. So they can't have public, private or anything, not even static. They automatically become static, if they are defined inside a static methos or initializer. and it kind of makes sense. Since we don't declare access modifiers for local variables, we can not define for local classes too. But Marcus Green's first exam has following question: public class MyClass1 { public static void main(String argv[]){ } /*Modifier at XX */ class MyInner {} } What modifiers would be legal at XX in the above code? 1) public 2) private 3) static 4) friend Answer: 1, 2, 3
So I am confused. Who is right here? Thanks in advance, Seema
Ash sav
Ranch Hand
Joined: Apr 14, 2001
Posts: 55
posted
0
Seema, I think you are confused with local classes and inner classe. In marcus green exam if you see the question carefully what he is asking is inner class (non static inner class is a member of enclosing class)and it can have any accessibility like public,default, protected, private. So the answer is correct. But local classes are defined in a block so they can not have any accessibility. I hope this helps. Ash
Seema Das
Ranch Hand
Joined: Mar 05, 2001
Posts: 78
posted
0
Oh god! didn't read the question correctly. didn't see the closing bracket after main. Thought he is defining class inside main method. Got the mistake. Thanks Ash!