Page 1 of 1

Re: About Question enthuware.ocpjp.v7.2.1243 :

Posted: Tue Jan 09, 2018 7:49 pm
by zukras
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?
A non static inner class may have static members.
Example:

Code: Select all

public class Outer {
    class Inner {
        static final int i = 0; // fine

        static final void print() { // compile error
            System.out.println("Inner static method");
        }
    }
}

Re: About Question enthuware.ocpjp.v7.2.1243 :

Posted: Tue Jan 09, 2018 9:38 pm
by admin
Yes, that is why this option is marked correct. A non-static inner class may have static fields if you make them final.

Re: About Question enthuware.ocpjp.v7.2.1243 :

Posted: Thu Jan 11, 2018 11:32 pm
by zukras
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.

Re: About Question enthuware.ocpjp.v7.2.1243 :

Posted: Fri Jan 12, 2018 12:07 am
by admin
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.