Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

variable access in inner class  RSS feed

 
Aaron Raja
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the rule:
If inner class is declared in a method then it can access only final variables of the particular method but can access all variables of the enclosing class.
look the code below carefully!!!

System.out.println(z);
will give you error because z is declared in Innermethod01 as int z = 1; not final!
wow!
so inorder to compile it make it final and declare in Innermethod01 as final int z =1.
-----------------------


[ June 11, 2007: Message edited by: Barry Gaunt ]
 
Cor Takken
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is your question?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!