This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class & Anonymous class :

 
geetha nagarajan
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of these statements r true?
1.Non static inner classes can't have static members.
2.Objects of top level nested class can be created without creating an outer instance.
3.Member variables in any nested class can't be declared final.
4.Anonymous class can't have constructors.
5.Anonymous class can't be static.
I thought the answers were 1,2,4.
But the answer is given as 2,4,5.
Anonymous class can be static,right:in the sense the context in which it's declared determines that.Though we don't explicitly use static to declare it so.
Pl.clarify,thanks in advance.
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.Non static inner classes can't have static members.
False. They can have static memebers but those members must be final.
2.Objects of top level nested class can be created without creating an outer instance.
True. A top level nested class is like any other top level class - there is no enclosing instance.
3.Member variables in any nested class can't be declared final.
False. Sure that can, and in the case of static variables they must be final.
4.Anonymous class can't have constructors.
True. They have no name so they can't have a constructor.
5.Anonymous class can't be static.
True. There is nowhere in the class declaration to put the static keyword. However, it can be declared in a static context (in a static method) this might be a semantic issue
 
Brian Lugo
Ranch Hand
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Geetha!
The first statement
1. Non static inner classes can't have static members.
is wrong because you can have
public static final in non static inner classes, i.e. you can declare static final constants.
Brian
 
geetha nagarajan
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave and Brain for the clarification.
Got it now .
By the way,where can i look up for such details reg.inner classes and anonymous class?
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geetha
Chack out the JLS section 8.1.2 for details on inner classes.
 
Vaibhav Shridish
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i really dont understand wht u r speaking ..
Plz refer section 7.3 Mughal and Ras..
Nonstatic inner class cannot have static members ...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic