About Question enthuware.ocpjp.v8.2.1437 :

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

Moderator: admin

Post Reply
admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

schchen2000 wrote:
One exception that it (the constructor) is always private.
Not always private. A constructor inside an enum CAN ALSO take default access specifier, i.e. leaving out any access specifier immediately before the constructor inside an enum is the same as the constructor having the default access specifier.

Schmichael
No, even if you leave out the access specifier (i.e. default), it will still be private. You may want to check out https://docs.oracle.com/javase/specs/jl ... #jls-8.9.2 :
In an enum declaration, a constructor declaration with no access modifiers is private.

In an enum declaration with no constructor declarations, a default constructor is implicitly declared. The default constructor is private, has no formal parameters, and has no throws clause.
If you like our products and services, please help us by posting your review here.

schchen2000
Posts: 106
Joined: Mon Mar 28, 2016 11:36 pm
Contact:

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

Post by schchen2000 »

Thank you. I learn something new everyday.

Schmichael

frodank
Posts: 1
Joined: Sat Mar 19, 2016 11:21 am
Contact:

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

Post by frodank »

Isn't this one correct?
System.out.println(MR.format("Rob", "Miller"));

You don't have to write "Title." before the enum-value if you do a static import on MR.

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

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

Post by admin »

frodank wrote:Isn't this one correct?
System.out.println(MR.format("Rob", "Miller"));

You don't have to write "Title." before the enum-value if you do a static import on MR.
It is possible but not in this case. Both, Title and TestClass are being defined in the same file. There is no package statement. So how will you import Title statically?
If you like our products and services, please help us by posting your review here.

nikitos
Posts: 21
Joined: Mon Oct 24, 2016 6:55 am
Contact:

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

Post by nikitos »

I do not agree with this:

class TestClass{   void someMethod()   {     System.out.println(MR.format("Rob", "Miller"));   } }

If enum is defined in not default package - above code will works if we add next import:

import static a.Coffe.LATTE;

But if enum is defined in default package - it will not work:)

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

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

Post by admin »

The problem statement says that Title is accessible where required. So that means Title is imported. Therefore, you have to use Title.MR instead of simply using MR.

HTH,
Paul.
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 86 guests