• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

final local class  RSS feed

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the modifier final can be applied to a local class..that means a final local class cannot have subclasses...does it mean that if the modifier final is not applied, u can extend the local class?....but the local class is local to the block in which it is created and cant be accessed outside that block...isn't it contradictory?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try it? Here's an example of a non-final local class being extended:


[ August 26, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that your reffering to inner classes, they can be extened inside the outer class.
 
Sandya Bhaskara
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx barry..i didn't get that idea....extending local class in the block in which it is declared....thanx a lot for the example too...but can u extend a local class outside the block in which it is declared?

hi benjamin..i wasn't refering to an inner class...inner classes can be extended even outside the class in which they r declared
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but can u extend a local class outside the block in which it is declared?




Best left as an exercise for the student... Write some code to test the hypothesis.
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If your definition of local class is a class declared inside a method; and you want to extend that "local" class "out side" the method, i don't think it is possible, since by the very definition of "local variables" the scope is limited to that block/method and convetionally all the local variables are destroyed once the method exists. The very reason of decalring them final is to extend their life times.

I hope i got your question right and this helps.

thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!