• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Reg. Inner classes

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the three statements below :
( only two are true )
1. Member variables of the Outer instance are always accessible to inner instance
regardless of the accessibility modifiers.
2. Member variables of the outer instance can never be referred to using only the variable name
within the inner instance
3. More than one inner instance can be associated with the same outer instance .
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it will be 1 & 3. 2 is false as you can refer the member variables of the outer instance by just their names as long as the name does not conflict with any local variable name or member variable name of the inner class.
 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right.
I just tried out naming a member variable of the inner clas
with the same name as the outer class.
Code compiles fine.


public class Q28fd {
int x = 1;
class Inner{
int x=3;
public void m() { System.out.println(" x = "+ x ) ; }

}
public static void main(String args[]) {
Q28fd.Inner i = new Q28fd().new Inner();
i.m();
}
}


Output : x = 3
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic