File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Nested class, inner class question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Nested class, inner class question" Watch "Nested class, inner class question" New topic
Author

Nested class, inner class question

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

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


cmbhatt
Omer Haderi
Ranch Hand

Joined: Sep 27, 2006
Posts: 42

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

Joined: Feb 28, 2007
Posts: 1707
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

Joined: Aug 03, 2002
Posts: 7729
You can also read section 14.3 of the Java Language Specification (Third Edition).
[ April 16, 2007: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Omer Haderi
Ranch Hand

Joined: Sep 27, 2006
Posts: 42
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
 
subject: Nested class, inner class question