This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding Inner Class" Watch "Regarding Inner Class" New topic
Author

Regarding Inner Class

Sujittt Tripathyrr
Ranch Hand

Joined: Jun 21, 2006
Posts: 96
Hi Everyone
public class TodayDate
{
public static void main(String s[])
{

int test=10;
class Second // Inner Class with in main function
{

void fun1(){
System.out.println(test); // accessing the local variable 'test'
}
}
}
}

In the above example while i am accessing the 'test' local variable then the program gives compile error.

Can anyone give the logic behind it.

Thanks in advance.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
A method-local class may be defined in a static method. In this case, the instance of method-local inner class can only access the static members of the enclosing class.
Vladimir Scheglov
Greenhorn

Joined: Jun 19, 2006
Posts: 20
local variable "test" must be final
Sujittt Tripathyrr
Ranch Hand

Joined: Jun 21, 2006
Posts: 96
That i know but i want the proper suggestions.

Thanks for the reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Inner Class
 
Similar Threads
INNER CLASSES
Method Local Inner class
why local classes in a static method?
method local inner class
doubt Method local inner class