Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Marcus Green Exam- On Inner classes

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.jchq.net/mockexams/exam2.htm#Answer%2044)


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
Ans By Marcus Green---
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


According to JLS , I had marked option "1" as false and I thought for the exam point of view "Inner classes cannot be static, because this is what JLS says"
But while going thru Maha Anna's Traps to be aware of in any SCJP test I found the following quote from Jim Yingst


However, the exam does apparently consider static member classes to be inner classes, even though this is clearly contradicted by the Nested Classes Specification and the JLS2. They don't make a big deal about it - they just call them "static inner classes". So, for the exam, pretend they're inner classes, and remember that in the real world, they aren't.


I think I also had a discuusion on this topic with Dan earlier that JLS is the ultimate for exam point of view..!!!
Then why this contradiction by Jim Yingst ?
Shud I answer option 1 as true of false in the exam ??
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In prior versions of the exam, we *did* use the more informal term "inner classes" for everything, including those marked "static", because this is the way most people talked about them in the past, even though the formal term was "top level nested class" for a static nested class, and "inner class" for a non-static nested class.
But because this is a case where the spec and "common use" were different, in 1.4 we did try to revise all the questions to use the term "nested" rather than "inner", when it mattered.
I cannot guarantee that we got them all (but I'll look again).
So... if you DO see a question that involves an inner class being static, YES -- an inner class can be marked static. Even though that turns the inner class into a "top level nested class", it is still an inner class before being marked static.
In other words, do not worry that the exam expects you to recognize the terminology distinction between "nested" and "inner". A static nested class *is* an inner class that's been marked "static". The fact that this modifier then *changes* the inner class into a nested class is not important to the real issue. The real issue is if you understand the *implications* of a static vs. non-static inner class. And that's all you're being tested on (and that's enough!)
Cheers,
Kathy
Author, "Getting in touch with your static nested class"
 
shweta mathur
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Kathy for clarifying this issue!!!
A word from the horse's mouth really helps.
 
Your mother was a hamster and your father was a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic