About Question enthuware.ocpjp.v8.2.1782 :

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

Moderator: admin

Post Reply
jme_chg
Posts: 29
Joined: Sun Feb 07, 2021 6:30 pm
Contact:

About Question enthuware.ocpjp.v8.2.1782 :

Post by jme_chg »

I tested the code but changed the enum so that it was just:

Code: Select all

enum Genre { DRAMA, THRILLER, HORROR, ACTION }; //***i.e. not static
but I thought this would cause:

Code: Select all

new Movie("Titanic", Movie.Genre.DRAMA, 'U'),                 
new Movie("Psycho", Movie.Genre.THRILLER, 'U'),                 
new Movie("Oldboy", Movie.Genre.THRILLER, 'R'),                 
new Movie("Shining", Movie.Genre.HORROR, 'U')); 
to fail compilation since
static members: can use enclosing class' name
non-static members: must use instance of enclosing class

but it still worked.

And also if have:

Code: Select all

new Movie("Titanic", new Movie().Genre.DRAMA, 'U'),                 
it fails compilation regardless of whether the enum is static/non-static.

Is there an explanation for this? :/

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

Re: About Question enthuware.ocpjp.v8.2.1782 :

Post by admin »

As per section 8.9 of JLS 11 specification:
A nested enum type is implicitly static. It is permitted for the declaration of a nested enum type to redundantly specify the static modifier.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: marpiva and 28 guests