About Question enthuware.ocpjp.v7.2.1457 :

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

Moderator: admin

Post Reply
pepness
Posts: 1
Joined: Tue Aug 12, 2014 8:53 pm
Contact:

About Question enthuware.ocpjp.v7.2.1457 :

Post by pepness »

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.

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

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

Post by admin »

No, it is correct usage. It is same as, (in this case, DOG, CAT, and FISH).

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sumanenthu
Posts: 23
Joined: Sun Feb 21, 2016 10:12 am
Contact:

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

Post by sumanenthu »

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?

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

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

Post by admin »

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

alamizsna
Posts: 1
Joined: Wed Oct 19, 2016 12:16 pm
Contact:

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

Post by alamizsna »

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."

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

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

Post by admin »

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

lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

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

Post by lenalena »

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)?

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

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

Post by admin »

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

horst1a
Posts: 37
Joined: Mon Jun 12, 2017 2:16 am
Contact:

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

Post by horst1a »

I read, that enum's Konstructor always must be declared private, isn't that true ?

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

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

Post by admin »

It is implicitly private. So even if you don't declare it explicitly as private, the compiler will make it private.
If you like our products and services, please help us by posting your review here.

horst1a
Posts: 37
Joined: Mon Jun 12, 2017 2:16 am
Contact:

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

Post by horst1a »

Thank you !

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests