Tried and it is correct only for class fields. Methods are class members as well but they cannot be declared as static. So, is it correct statement saying that inner class can have static members?
public class Outer {
class Inner {
static final int i = 0; // fine
static final void print() { // compile error
System.out.println("Inner static method");
}
}
}
But correct answer is "A non static inner class may have static members". Since method is a member of class as well why then the is not "A non static inner class may have static fields."? Details but I think terminology should be used right.
I understand what you are saying but the statement is legally correct. It does not say that all kinds of members can be static. It just says it may have static members. field is a member and it can be static.
Yes, "fields" would be more clear but you may expect some ambiguity in the real exam as well.
If you like our products and services, please help us by posting your review here.