aspose file tools*
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
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