For the following question: Which of the following are true statements?
a. An anonymous class is implicitly abstract. b. An anonymous class is implicitly final. c. An anonymous class is implicitly static. d. A static reference variable can reference an instance of an anonymous class. e. An anonymous class declaration must have at least one explicit constructor declaration. f. An anonymous class declaration can have more than one explicit constructor declaration.
Answer:b,d
I'm confused with answer D. How can we create a A static reference variable can reference an instance of an anonymous class?
Hi, Anonymous class means anonymous inner class: Anonymous inner class comes in two flavours, one that extends another class and other that implements an interface.
d. A static reference variable can reference an instance of an anonymous class. Yes you can do this. For that matter you can have a static refernce variable that can refer to an instance of any type of class Try this code class A { static B bStatic = new B(); }
class B {} It only means that bStatic is a static member of class A. and you can also have class A { static B bStatAnnony = new B() { }; // Here bStatAnnony points to an instance of a class that extends B but it has no name }