Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Accessing shadowed members of an enclosing class

Reply
Thread Tools

Accessing shadowed members of an enclosing class

 
 
Bernd Fuhrmann
Guest
Posts: n/a
 
      10-15-2005
Hi!

I was just wondering if it is possible to access shadowed variables from
within an inner class. Example:

public class Outer {
public int a;//#1
public class Inner {
public int a;//#2
public void dosth() {
System.out.println("a from inner is "+a);
// Is there any way to access a from Outer
// within this context?
}
}
}

Is there any way to access the member a of Outer within Inner?

Thanks in advance,
Bernd Fuhrmann
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      10-15-2005
Bernd Fuhrmann <(E-Mail Removed)> writes:
>Is there any way to access the member a of Outer within Inner?


Outer.this.a

 
Reply With Quote
 
 
 
 
Bernd Fuhrmann
Guest
Posts: n/a
 
      10-15-2005
Stefan Ram wrote:
> Bernd Fuhrmann <(E-Mail Removed)> writes:
>> Is there any way to access the member a of Outer within Inner?

>
> Outer.this.a
>

Thanks says
Bernd Fuhrmann
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-15-2005
On Sat, 15 Oct 2005 21:40:13 +0200, Bernd Fuhrmann
<(E-Mail Removed)> wrote or quoted :

>public class Outer {
> public int a;//#1
> public class Inner {
> public int a;//#2
> public void dosth() {
> System.out.println("a from inner is "+a);
> // Is there any way to access a from Outer
> // within this context?
> }
> }


In general you can access nested elements with Outer. and Inner.
e.g.Outer.this Inner.a


See http://mindprod.com/jgloss/nestedclasses.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
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
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
Can nested class members access private members of nesting class? CoolPint C++ 8 12-14-2003 02:30 PM
Re: How does an inner class (non-static) refer to members of it's enclosing class? Jayaram Java 0 07-18-2003 05:03 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