posted 21 years ago
Q#ID : 958227370580
which of the following statements regarding inner classes are true ?
1. A non static inner class may have static members
2. Anonymous inner classes cannot have any 'extends' or 'implements' clause.
3. Anonymous inner classes can only be created for interfaces
4. Anonymous inner classes can never have initialization parameters.
5. Anonymous inner classes cannot be static.
the answer given is : 1,2,5
I tought the only 2 and 5 are correct,
for answer 1, JQ+ said :
Option Comment : "If you make them final"
General Comment :
"...Erlier, Non static inner clasess were not allowed to have static fields at all. THIS RULE IS NOW MODIFIED, and the new rule says that :
The third paragraph of the section members that can be marked static is amended to make an exception and allow inner classes to declare static FINAL fields that are compile time constants as members.
Ex.
public class Outer {
class inner {
static final int k = 0;
}
}
Geee....IS IT TRUE ???
I tried, but it give me compile error !!
thank's
stevie