• 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

Inner class

 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A question from Marcus exam:
Question 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

The answer is:


1) An inner class may be defined as static
4) An inner class may extend another class
A static inner class is also sometimes known as a top level nested class. There is some debate if such a class should be called an inner class. I tend to think it should be on the basis that it is created inside the opening braces of another class. How could a programmer provide a constructor for an anonymous class?. Remember a constructor is a method with no return type and the same name as the class. Inner classes may be defined as private


I understand that these definitions are little bit personal but from exam point of view, would it be correct to include option 1 in the answer?
Thanks
[ June 16, 2003: Message edited by: Barkat Mardhani ]
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Barkat,
if u follow the JLS, option 1 will not be valid. as

An inner class is a nested class that is not explicitly or implicitly declared static

(JLS 8.1.2)
so it would be better to call such class (static nested) 'nested' instead of 'inner'. since once it is declared static it is still nested but not inner any more.
i think JLS suggests to think of inner class the one that is nested and NOT STATIC (and not annonymous too, as that is unnamed).

this expression does not in anyway devalue/dishonour personal preferences and only suggests an approach purly for exam purpose.
[ June 17, 2003: Message edited by: G Nadeem ]
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Khalid Mogul calls local classes as inner classes. Further in the text he classifies that local classes can be static or non-static.
Do we have standard definition from exam point of view?
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sticking with "static nested" for static member classes, and then "inner class" or "nested" for non-static member classes. Preferably just "inner class" for non-static nested class.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic