All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Tue Aug 12, 2014 8:57 pm 
Offline

Joined: Tue Aug 12, 2014 8:53 pm
Posts: 1
There is a typo in the last declaration:

Enum constants (here, DOG, CAT, and FISH) must be declared before anything else. Therefore, String name; is invalid here.

Should be:

Enum constants here (DOG, CAT, and FISH) must be declared before anything else. Therefore, String name; is invalid here.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Tue Aug 12, 2014 11:53 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6804
No, it is correct usage. It is same as, (in this case, DOG, CAT, and FISH).

HTH,
Paul.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Sun Mar 20, 2016 5:09 am 
Offline

Joined: Sun Feb 21, 2016 10:12 am
Posts: 23
I got from somewhere that Enum constants are initialized through the static initializer methods. Then how can we use 'this' keyword in the constructor in option 3?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Sun Mar 20, 2016 9:46 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6804
You can always use "this" keyword in any constructor.
It is really very difficult to comment on the correctness of a statement when taken out of context but the statement, " Enum constants are initialized through the static initializer methods." doesn't look correct to me.
-Paul.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Wed Oct 19, 2016 12:18 pm 
Offline

Joined: Wed Oct 19, 2016 12:16 pm
Posts: 1
As I know Enums are always final, so how come this ->Option 3: "Here, CAT is actually an instance of an anonymous subclass of Pets."


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Wed Oct 19, 2016 1:32 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6804
They are not always final. If you create anonymous subclass as done in option 3, Pets will not be made final by the compiler. For CAT, the compiler will create a class named Pets$1, which will be final.

HTH,
Paul.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Fri May 19, 2017 2:03 pm 
Offline

Joined: Tue Feb 21, 2017 4:24 pm
Posts: 56
For option 2, why isn't static String prefix considered effectively final? Or it is effectively final but enum can only access static fields that are explicitly finals? Or the concept of effectively final doesn't apply to static fields (because they could be modified outside of the declaring class)?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Fri May 19, 2017 10:00 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6804
The concept of effectively final applies only the method parameters and method local (aka automatic) variables. It does not apply to class or instance variables. The reason is simple. Method parameters and automatic variables are kept on the stack space and go out of scope as soon as the method is over. class and instance variables are stored on the heap space and never go out of scope (as long as the class/object is there) so there is no telling when their value might change if they are not declared explicitly final.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Thu Oct 12, 2017 3:06 am 
Offline

Joined: Mon Jun 12, 2017 2:16 am
Posts: 31
I read, that enum's Konstructor always must be declared private, isn't that true ?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.ocpjp.v7.2.1457 :
PostPosted: Thu Oct 12, 2017 3:09 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6804
It is implicitly private. So even if you don't declare it explicitly as private, the compiler will make it private.


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 9 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