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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding Inner Class" Watch "Regarding Inner Class" New topic

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

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:
subject: Regarding Inner Class
Similar Threads
method local inner class
why local classes in a static method?
doubt Method local inner class
Method Local Inner class