All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1243 :
PostPosted: Tue Jan 09, 2018 7:49 pm 
Offline

Joined: Fri Jun 02, 2017 4:57 pm
Posts: 2
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?

Quote:
A non static inner class may have static members.


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

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


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1243 :
PostPosted: Tue Jan 09, 2018 9:38 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6920
Yes, that is why this option is marked correct. A non-static inner class may have static fields if you make them final.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1243 :
PostPosted: Thu Jan 11, 2018 11:32 pm 
Offline

Joined: Fri Jun 02, 2017 4:57 pm
Posts: 2
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.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1243 :
PostPosted: Fri Jan 12, 2018 12:07 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6920
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.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL/ThatBigForum