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

Static Inner Class Question

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw this question on a mock exam, but I don't always trust their answers. I hear that inner classes are big on the certification exam, so a thorough explanation of this question would be helpful. My expertise on inner classes is pretty shallow.
Which statements about static inner classes are true? (Choose two)
A. A static inner class has no references to an instance of the enclosing class.
B. Static members of a static inner class can be referenced using the class name of the static inner class.
C. A static inner class requires a static initializer.
D. A static inner class requires an instance of an enclosing class.
E. A static inner class has access to the non-static members of the outer class.
I know that Option E can be eliminated because a static inner class does not have access to the other class's non-static members.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think maybe the wording could be a little better, but I would agree with A and B if they went more like this:
A. A static inner class has no (implicit) references to an instance of the enclosing class.
B. Static members of a static inner class can be referenced using the (fully resolved) class name of the static inner class.
I might even try to add something to B about how the members must be visible (ie not private, etc).
HTH,
Chris
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think A and B are the answers. Well you should consider static inner classes as any other static member of a class. Like for example

can be a class member so can a static class.
Secondly, just like for any static member you do not need a reference to its enclosing class.
e.g.
class Myclass{
static inner{
static int x;
}
}
an instance of the inner class can be created just be refering to Myclass.inner you dont need a reference to the enclosing class.
Thirdly for any static member of the inner class u can directly access it too by Myclass.inner.x.
I hope this helps..
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Christopher, the wording of the answers is a bit misleading and could be better. But you can pretty quickly dismiss the last three options if you understand static members of a class.
And as Saniya stated, static inner classes are like any static member of a class. The last three options do not apply to static members of classes, and if the question states that there are two answers to the question, then A and B have to be correct.
Sometimes it will be better to eliminate answers you know are wrong, especially since the exam will tell you how many answers it is expecting.
HTH,
Eric
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic