File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes LOCAL inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "LOCAL inner class" Watch "LOCAL inner class" New topic

LOCAL inner class

sunilkumar ssuparasmul
Ranch Hand

Joined: Dec 13, 2000
Posts: 142
"Since the names of local classes are not visible outside the local context, references of these classes cannot be declared outside. So their functionality could be accessed only via super-class references (either interfaces or classes). Objects of those class types are created inside methods and returned as super-class type references to the outside world. This is the reason that they can only access final variables within the local block. That way, the value of the variable can be always made available to the objects returned from the local context to outside world."

can somebodt explain the above context with a example -plzzzz
thanks in advance
"Winners don't do different things
They do things differently"

"Winners don't do different things<br /> They do things differently"
Cherry Mathew
Ranch Hand

Joined: Dec 26, 2000
Posts: 159
it means that we cant create a reference of the local inner class outside and we have to create an object of the same and return it.
consider the case when we r referencing to a non-final local variable inside our local inner class.the local variables r destroyed once the control comes out of the function but the object which is returned by the function still refers to it and this will cause a problem . now if that vasriable is final then java compiler will create a new instance variable for the local inner class and pass it when the object is initialized . this is done by the compiler not the runtime environment. this is bcos the compiler is sure the variable wont change afterwards .
this i think will create u r doubt but i ve got a doubt about this i hope someone will answer this
i read that i can have a blank final vasriable inside a local inner class what if i dont initialize this varable before i create an instance of the local inner class or is there that restriction
wood burning stoves
subject: LOCAL inner class
It's not a secret anymore!