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

Question abt Method Local Class

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider following code

This is an example of declaring an (non-anonymous) inner class within a method, i.e. yo( ). The rules of applying modifiers to this type of inner class is similar to that of local variables. You cannot marked the this type of inner class with the following modifiers : static, private, protected, public, transient, volatile, native, and synchronized. The only modifiers you are allowed to used on them are : final, abstract and strictfp (and of course without any modifiers at all).

Now My question is if we say "Rules which are applied to local method class
is same as rules applied to Local variable" Then how can we apply abstract and strictfp keywords to local method class.

Thanks
 
Suhas Wadadekar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion abstract and trictfp are class modifiers. Anything that is method local other than a class is a variable declaration and initialization and/or a method call.
So a variable cannot have the modifiers: abstract and strictfp, anywhere.
Hence the reason.
 
Douglas Chorpita
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should read:

The rules of applying ACCESS modifiers to this type of inner class is similar to that of local variables.

Think about it. A method-local class differs from other types of classes in terms of SCOPING, which is related to ACCESS.

The modifiers "strictfp", "abstract" and "final" have nothing to do with SCOPING and ACCESS. "strictfp" is about floating point arithmatic. "abstract" and "final" are about SUBCLASSING.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic