• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing private inner class members

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible for an outer class method to access private members of the inner class?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
//Inner class is a static class, i.e. top-level class
//then can you access to private member of the inner class
public class COuter
{
String str = "Hello";
public void myMethod()
{
System.out.println(str + " " + CInner.strInner + "!");
}
static class CInner
{
private static String strInner = "Sahir Shah";
}

public static void main(String args[])
{
COuter outer = new COuter();
outer.myMethod();
}
}
//regards

//Matthias
 
Sahir Shah
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me rephrase that. Is it possible for an outer class method
to access the private members of a non-static inner class ?
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Have you tried it?? Check this out-

[This message has been edited by Ajith Kallambella (edited December 21, 2000).]
 
Sahir Shah
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yes I did notice it. The reason why I brought this up was because it struck me as odd that the documentation is mysteriously silent about this. I smell a rat. Are they trying to coverup some weakness or am I being paranoid ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic