• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Anonymous Inner class

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following is true ??

1.An anonymous inner class may be declared as final

2.An anonymous inner class may be declared as private

3.An anonymous inner class can implement multiple interfaces

4.An anonymous inner class can access final variables in any enclosing scope
5.Construction of an instance of a static inner class requires an instance of the enclosing outer class

Here option 3 and 5 are false because static inner class doesnt require outer class instance and Anonymous inner class extends only one class or implements one interface..

Anonymous inner classes are implicitly final right..

Then what about the other??
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1.An anonymous inner class may be declared as final
2.An anonymous inner class may be declared as private



I don't think anonymous inner class has modifier beside what inherited from it parent (the inner-class). Modifier used to interact (is-a or has-a) with other classes.
But anonymous class only used once, it has no name.

And I don't have any idea where we can put a modifier in anonymous class



We can only extend 1 class or interface in anonymous class


4.An anonymous inner class can access final variables in any enclosing scope


Like other inner class, it can access any outer class method & property. And final local variable.


5.Construction of an instance of a static inner class requires an instance of the enclosing outer class


because it's static we don't need outer class' instance

CMIIW
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jimmy halim:
I don't think anonymous inner class has modifier beside what inherited from it parent (the inner-class).


In the JLS, Section 15.9.5, it is written:

An anonymous class is never abstract (�8.1.1.1). An anonymous class is always an inner class (�8.1.3); it is never static (�8.1.1, �8.5.2). An anonymous class is always implicitly final (�8.1.1.2).

Yours,
Abdul Rehman.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know...

In terms of the exam, when it states
"1.An anonymous inner class may be declared as final "
is the answer going to be false, since you cannot apply modifiers to an anonymous inner class. Or will it be true, becuase anonymous inner classes are implicitly final?

It seems that you could get this question wrong even if you understood anonymous classes?

Cheers
Matt
 
jimmy halim
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Does anyone know...

In terms of the exam, when it states
"1.An anonymous inner class may be declared as final "
is the answer going to be false, since you cannot apply modifiers to an anonymous inner class. Or will it be true, because anonymous inner classes are implicitly final?

It seems that you could get this question wrong even if you understood anonymous classes?



Yes I also wondering what will be the right answer, it's ambiguous
At first sight I though the question is about declaring explicitly.

Thanks alot to Abdul Rehman for the JLS info

Maybe the questions should be clearer with stating if it's explicitly or not
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic