This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Inner Class

 
Rajan Narayanan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi J'pros,
i'd dbt in Inner class, i was taking one mock exam, the question abt inner class abt the scope of variables..which are the variables can be placed in place XX, my answer is ID and nn but to my surprise name is also in the answer list.. when i went thru RHE it says if a inner class is defined inside a method of a outer class only variables accessible is if it's marked as FINAL then how name is accessible.
Any explanation is highly appreciated.
public class Outer{
private static final int ID = 5;
private String name ;
public voic methodA(final int nn){
int serialIN = 22;
class Inner{
void showresult(){ //Here the parantesis is other way like this way }first of it's printing mistake..
System.out.println("Rslt="+XX);
}
}
new.inner.showresult();
}
}
 
aparna kodali
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
Inner class, unless 'static',have access to the variables of the enclosing class instance. ADDITIONALLY, inner classes defined in method scope have access to 'final' variables of the enclosing method.
Hope u got the point.
kodali
 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, in case of inner classes defined in methods..
Variables declared as final in enclosing method, all other
variables of the top level class can be accessed.
- cheers
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A local inner class has free access to all the member variables of the outer class AND the final variables defined in the method within which the inner class is defined
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic