Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: How does an inner class (non-static) refer to members of it's enclosing class?

Reply
Thread Tools

Re: How does an inner class (non-static) refer to members of it's enclosing class?

 
 
Jayaram
Guest
Posts: n/a
 
      07-18-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Bent C Dalager) wrote in message news:<bf7rk2$qp2$(E-Mail Removed)>...
> In article <(E-Mail Removed)>,
> Wolfgang <(E-Mail Removed)> wrote:
> >Peter van der Linden writes that a good way to think of of an inner
> >class object is that, because it is associated with an instance of
> >it's enclosing class, it really has two "this" pointers: one to itself
> >and one to its enclosing object.
> >
> >What does that look like in practice?

>
> class Outer
> {
> int member;
> class Inner
> {
> public void printOuterMember()
> {
> System.out.println(member); // prints Outer's member
> }
> }
> }
>
> >
> >How does an inner class refer to members of it's enclosing class? And
> >what happens when an inner class member has the same name as a member
> >of the enclosing class?

>
> You have to qualify it if you want to bypass the inner one:
>
> class Outer
> {
> int member;
> class Inner
> {
> int member;
> public void printMembers()
> {
> System.out.println(member); // prints my own inner member

// OR expressed as
System.out.println(this.member);

> System.out.println(Outer.member); // prints Outer's member

// OR expressed as
System.out.println(Outer.this.member);
> }
> }
> }

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
referring to static fields of enclosing class from static inner class? bugbear Java 4 08-23-2006 08:26 AM
Referencing enclosing class from inner class Jonathan Java 3 07-31-2006 12:30 PM
Enclosing class instance availability during inner class initialization Stanimir Stamenkov Java 4 07-14-2006 01:13 PM
Accessing shadowed members of an enclosing class Bernd Fuhrmann Java 3 10-15-2005 09:36 PM
Re: How does an inner class (non-static) refer to members of it's enclosing class? Tor Iver Wilhelmsen Java 0 07-18-2003 08:41 AM



Advertisments