Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Method Local 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 "Method Local Inner Class" Watch "Method Local Inner Class" New topic

Method Local Inner Class

Phal Ach
Ranch Hand

Joined: May 09, 2008
Posts: 54
Hi. Below is from, 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

Joined: Apr 27, 2008
Posts: 342
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 ]

SCJP 5 (98%) - SCBCD 5 (98%)
Phal Ach
Ranch Hand

Joined: May 09, 2008
Posts: 54
Looks good Ralph. Thanks
I agree. Here's the link:
subject: Method Local Inner Class
It's not a secret anymore!