Author | Topic: Inner Class |
deneb shah greenhorn |
posted March 14, 2000 08:32 PM
Why the inner class declared in a method can acces only the final variables.. one of the reasons i read was that since final variables are constants they exist even after the method is over. does that means that the inner class defined inside a method exists beyond the method. could i somehow access the inner class. // sorry for a silly questions... ------------------
|
Tony Alicea sheriff |
posted March 14, 2000 08:40 PM
Sure the local class object created in a method could exist afterward. Think of the case in which a method returns an object created inside the method in a local class.
|
Jim Yingst sheriff |
posted March 14, 2000 09:45 PM
Also- an inner class can access more than final variables. It can access final local variables and it can access all member (class and instance) variables of the outer class - whether final or not.
|
art unregistered |
posted March 15, 2000 10:04 AM
Am i right in understanding that an inner class defined inside a method cannot access local variables in other member functions of outer class. Since the scope of any local variable is only within the method where it is defined. There was a question on Marcus Green mock exam 2 which highlighted on this. I did not look it carefully and got it wrong. Can someone verify this please.
|
maha anna bartender |
posted March 15, 2000 10:51 AM
Originally posted by art, An inner class defined inside a method cannot access local variables in other member functions of outer class. Since the scope of any local variable is only within the method where it is defined. Yes you are right. Local var have scope only within the block where it is defined. So only the vars/expressions/statements which are inside the same block can have access to them. [This message has been edited by maha anna (edited March 15, 2000).]
|
| | |