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

// inner class question

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following question is from Marcus Green Mock exam 2
44)Which of the following statements are true
1) An inner class may be defined as static
2) There are NO circumstances where an inner class may be defined as private
3) A programmer may only provide one constructor for an anonymous class
4) An inner class may extend another class
answers are 1) and 4)
I dont agree with 1)
As per JLS 8.1.2
An inner class is a nested class that is not explicitly or implicitly declared static
So what I understood from this is static inner class (ie. top level nested class) and local class in static methods are not inner classes
Correct me if I am wrong
Thanks in advance
Megan
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


As per JLS 8.1.2
An inner class is a nested class that is not explicitly or implicitly declared static


I believe in above quote the phrase "An inner class" should be replaced with phrase "A non-static inner class".
There are four type of nested classes:
1. Top level nested classes or interfaces (always static)
2. Non static inner class (always non-static)
3. Local class (can be static or non-static)
4. Anonymous class (can be static or non-static)
The last three are collectively called "inner class". Because Local and Anonymous classes are deemed inner and they can be static, there following statement should be true:
"The inner classed can be static."
So I would say that Marcus answer is correct. If everyone reading this post agrees, then Sun will need to correct its JLS quoted above.
Thanks
Barkat
 
I was her plaything! And so was this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic