• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

a question about anonymous question

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1
Which of the following statements are true?
A) An anonymous class cannot have any constructors
B) An anonymous class can only be created within the body of a method
C) An anonymous class can only access static fields of the enclosing class
D) An anonymous class instantiated and declared in the same place.

i think the answer is ABD
however the answer given is AD
why?
Q2
Is there any difference between anonymous inner class and anonymous class?
thanks
[ March 04, 2002: Message edited by: michael wang ]
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use an anonymous class inside a constructor, which is not a method. Or how about this example:

There's two examples that prove B is false.

An inner class is a class defined inside the instance of another class. An anonymous class just means you are creating an instance of a subclass of a class without giving the subclass a name. So they are two different things. That being said, you can't define a top-level anonymous class; the only place you can define an anonymous class is within something else. So in practice, your anonymous class is always going to be a nested class.
 
michael wang
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's very clear
thanks Rob
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic