File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested class, inner class question

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which of the follow are true statements.
a. A local class is declared within a method, constructor or block.
b. An anonymous class is always a local class.
c. A local class is a nested class.
d. A local class is a member class.
e. A local class is always a named class.


Source: Danchisholms

Answer is a, c, e

My doubts:
1- Can't a local class be anonymous? (regarding option e)
2- Can't an anonymous class be defined in a class level. (regarding option b)
3- Local class is a member class, what is member class all about, I understand member class means member of a class. Right?


Please help!


Regards,
cmbhatt
 
Omer Haderi
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My doubts:
1- Can't a local class be anonymous? (regarding option e)
2- Can't an anonymous class be defined in a class level. (regarding option b)
3- Local class is a member class, what is member class all about, I understand member class means member of a class. Right?


1- According to David Flanagan (author of Java in a Nutshell) "An anonymous class is essentially a local class without a name. Instead of defining a local class and then instantiating it, you can often use an anonymous class to combine these two steps... an anonymous class is defined by a Java expression, not a Java statement. This means that an anonymous class definition can be included within a larger Java expression... an anonymous class behaves just like a local class, and is distinguished from a local class merely in the syntax used to define and instantiate it."

2- How could you create an anonymous inner class as class member ?

3- Yes you are right, member class means member of a class, Local class is NOT a member class (as it is not in the answers).
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Omer for nice explanation,
but the question remains "A local class is always a named class" the option e that is true (as said).

I say, local class can be anonymous also (not necessarily a named class only).
Please make it clear whether option e is correct or not!


Regards,
cmbhatt
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also read section 14.3 of the Java Language Specification (Third Edition).
[ April 16, 2007: Message edited by: Barry Gaunt ]
 
Omer Haderi
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As always the JSL has the answer.

"A local class is a nested class (�8) that is not a member of any class and that has a name. ..."

Thanks Barry.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic