• 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

the Quession about static of inner class

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What a static inner class can access select one
A. Any variables in the enclosing scope
B. Final variables in the enclosing scope
C. Static variables declared in side the method
D. Static variables declared in side the outer class

I think b is right but ans is d
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is D.
 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by FEI NG:
The answer is D.


IF the Q is "What a inner class can access select one
"
Which one is right? Thanks
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A non-static inner class can access all the members (i.e.,data and methods) in the enclosing class. So, your answer will be A (in the given choices), but it is part of the correct answer bcoz it can also access all the methods of the enclosing class.
Uma
 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Uma very much~~!
But which difference of enclosing scope with In Side the outer class
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"But which difference of enclosing scope with In Side the outer class...". I could not understand what do you mean by this. Could
you frame the words in a different way?
- Uma
 
Fei Ng
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hades Pan:
IF the Q is "What a inner class can access select one
"
Which one is right? Thanks



agree with Uma.
answer would be A.
 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh Sorry My English is too bad
I want ask What the condition is "variables in the enclosing scope
"
and What is "variables declared in side the outer class"
 
Fei Ng
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Uma Viswanathan:
"But which difference of enclosing scope with In Side the outer class...". I could not understand what do you mean by this. Could
you frame the words in a different way?
- Uma


uma, the idea of inner classes is that you can access enclosing var. For example, in listener you can have inner class implement or extend some listener. That way you could access enclosing var or method. Why you want this?? becuase when some event happens you usualy want something to happen right?? and thats usually not within the listener class itself but some other classes.
Now "other classes" can now have inner class(listener) which has access to "other classes" methods and var. It easier for listener to access the var or method. If not you have to pass "other class" reference to the listener.
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hades Pan:
It's OK...no problem with english. I could not understand your question. That's why i had asked to reframe it...
I feel that there is no difference between "enclosing scope" and
"inside the outer class".
"Enclosing scope of inner class" and also "inside the outer class" refer to the "enclosing class".
Some one correct me, if i am wrong...
PS:
See you tomorrow. I am leaving the office now since it is late...
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi FEI NG,
Thanks. I too understand the same...but Hades Pan's question is different. Confirm whether what i answered for his question is correct or not...
Uma
 
Fei Ng
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh.. i am off the topics?? sorry.

 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Uma Viswanathan again~~!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have mistaken static inner class with the inner class in the method scope. The latter one can only access the final variable in the method
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is "enclosing scope" ?
is it the enclosing method that the inner class is in, or the outer class?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
an inner class is non static nested class.an inner class can be
local, anonymous or non static member class.
if the innerclass is non static member class enclosing scope is the outer class.
if the innerclass is local class(class inside method) then that method directly encloses the class.the class is also enclosed by the outerclass.so the enclosing scope is the method(in which the class is defined) as well as the outerclass.
hope this helps
kinnu.
 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ruthie:
I think you have mistaken static inner class with the inner class in the method scope. The latter one can only access the final variable in the method



Can we speack that local class can only access the Final variables in the enclosing scope
???
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) A static inner class (i.e, a class inside the class) can access only the static members of the outer class (i.e, enclosing class)
2) A non-static inner class can access all the members of the enclosing class.
3) A static local class (a class inside method) and static anonymous inner class can access the final local variables of the enclosing method and the static members of the outer class
4) A non-static local class and non-static anonymous inner class can access the final local variables of the enclosing method and all the members of the outer class.
Hope this helps...
Uma
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enclosing scope:
For an inner class within the class: enclosing scope is the "outer class"
For an inner class within the method (and also for anonymous inner class): enclosing scope is "the method which contains and the outer class"
Hope this helps...
Uma
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey c my posting(intereting inner classes)
u will find ur problem solved inshallah.
------------------
Muhammad Hussain
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic