About Question enthuware.ocajp.i.v7.2.1079 :

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

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1079 :

Post by ETS User »

import static com.foo.*;
Bad syntax. Package import does not use static keyword.

it´s is correct?

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

Re: About Question enthuware.ocajp.i.v7.2.1079 :

Post by admin »

You have pasted option C, which is marked as incorrect. You are right package import does not use static keyword, but com.foo could be a class name also (although it is not in this case).

The correct option is D.

HTH,
Paul.

Deepa

Re: About Question enthuware.ocajp.i.v7.2.1079 :

Post by Deepa »

I want to know,
1. what is wrong in the syntax shown in option (ii) as per as i understand it declares only package name - import static <com.foo>.*;
Package name
thats why it is a bad syntax?
2.And option (v) is wrong, is it because the static keyword is not there?
3.I didn't understand the explaination for option (iv) " static import of LOGICID is NOT required because Y is accessing LOGICID through X ( X.LOGICID). Had it been just System.out.println(LOGICID), only one import statement: import static com.foo.X.*; would have worked.".

Please help!

Regards,
Deepa

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

Re: About Question enthuware.ocajp.i.v7.2.1079 :

Post by admin »

Deepa wrote:I want to know,
1. what is wrong in the syntax shown in option (ii) as per as i understand it declares only package name - import static <com.foo>.*;
Package name
thats why it is a bad syntax?
I think in isolation, syntactically it is correct . It is not valid in this case because com.foo is not a class, it is a package and you can't import a package using "static".
Deepa wrote: 2.And option (v) is wrong, is it because the static keyword is not there?
Yes.
Deepa wrote: 3.I didn't understand the explaination for option (iv) " static import of LOGICID is NOT required because Y is accessing LOGICID through X ( X.LOGICID). Had it been just System.out.println(LOGICID), only one import statement: import static com.foo.X.*; would have worked.".
Since you are already importing class X, you can access its LOGICID using X.LOGICID. If you don't import class X, then you can't do X.LOGICID. In that case, you can import LOGICID statically using: import static com.foo.X.*; and then access LOGICID directly i.e. System.out.println(LOGICID). Notice that it cannot use X.LOGICID now.

HTH,
Paul.

Wisevolk
Posts: 33
Joined: Thu Jul 18, 2013 6:06 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1079 :

Post by Wisevolk »

For Answer 2 I think the explication should be foo is not a class and not :
"Bad syntax. Package import does not use static keyword."

EelcoD
Posts: 10
Joined: Sat Jan 24, 2015 8:09 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1079 :

Post by EelcoD »

I also didn't understand the explanation very well.
or option 2 I'd say:

Bad Syntax. When importing you can only use the keyword static on static classes or fields and on this line a whole package is imported.

sivarama2794
Posts: 4
Joined: Sat Aug 06, 2016 11:07 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1079 :

Post by sivarama2794 »

Hello admin,
Can you explain a little more on option 3 ''import static com.foo.X.*;'' I didn't get this part.

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

Re: About Question enthuware.ocajp.i.v7.2.1079 :

Post by admin »

"import static com.foo.X.*;" implies that you are importing static members of class X. So instead of using X.LOGICID in your code, you can just use LOGICID. But that will not help here because class X is not in the same package as Y. So Y cannot access X directly without importing X's package, which is com.foo.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 9 guests