About Question enthuware.ocpjp.v7.2.1243 :

Moderator: admin

zukras
Posts: 5
Joined: Fri Jun 02, 2017 4:57 pm
Contact:

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

Post by zukras » Tue Jan 09, 2018 7:49 pm

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");
        }
    }
}

admin
Site Admin
Posts: 7451
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Tue Jan 09, 2018 9:38 pm

Yes, that is why this option is marked correct. A non-static inner class may have static fields if you make them final.
If you like our products and services, please help us by posting your review here.

zukras
Posts: 5
Joined: Fri Jun 02, 2017 4:57 pm
Contact:

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

Post by zukras » Thu Jan 11, 2018 11:32 pm

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.

admin
Site Admin
Posts: 7451
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin » Fri Jan 12, 2018 12:07 am

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.

Post Reply

Who is online

Users browsing this forum: Mark7777 and 1 guest