wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a question about anonymous 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 "a question about anonymous question" Watch "a question about anonymous question" New topic
Author

a question about anonymous question

michael wang
Ranch Hand

Joined: Feb 06, 2002
Posts: 35
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 ]

--<br />a java beginner from China
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
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.


Rob
SCJP 1.4
michael wang
Ranch Hand

Joined: Feb 06, 2002
Posts: 35
it's very clear
thanks Rob
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: a question about anonymous question