• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Nested class, inner class question

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic