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

anonymous class

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Here I can say A,C,D are correct
Please comment
thanks in advance
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Payal,
I'll do more than comment, I will prove with a code example that the only correct answers are A and D.
The following code shows an anonymous class being created outside of any method (B) and also shows an anonymous class accessing both static and nonstatic variables of the enclosing class (C).

Regards,
Manfred.
[This message has been edited by Manfred Leonhardt (edited July 26, 2001).]
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A and D are correct, as Manfred has explained
-- Sandeep
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you guys think the example which manfred gave are created inside a method? The other place only get the return value which is created in the method. Why B is not the answer is because we can create anonymous class inside a class but out of any method ---in Initializer or Initializer block. So i think answer should be A, D.
Jason
[This message has been edited by Jason Li (edited July 26, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic