About Question enthuware.ocpjp.v7.2.1243 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

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

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

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

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

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

Post 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.
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 »

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: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 53 guests