Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!