Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method Local Inner Class

 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Below is from geekevaluation.com, regarding method local inner class. I know that final variables of methods can only be accessed by its method local inner class. Then why not in below mentioned code?




Here 'a' is a final variable. Still at Line 4, there is a compiler error. Somebody please give me a proper explanation for this. Thanks.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two mistakes:

1. Within a class definition only declarations of variables, methods, blocks, etc. are allowed, but no statements like "a = 19;". The follwing example will help: 2. You can't assign a value to a final variable within a local class.

The following would work:


[ July 08, 2008: Message edited by: Ralph Jaus ]
 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks good Ralph. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic