Page 1 of 1

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

Posted: Sun Jun 17, 2012 10:49 pm
by ETS User
import static com.foo.*;
Bad syntax. Package import does not use static keyword.

it´s is correct?

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

Posted: Mon Jun 18, 2012 5:54 am
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.

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

Posted: Thu Dec 13, 2012 9:09 am
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

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

Posted: Thu Dec 13, 2012 10:06 am
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.

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

Posted: Sun Aug 04, 2013 12:08 pm
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."

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

Posted: Sat Jan 24, 2015 8:13 am
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.

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

Posted: Tue Aug 09, 2016 3:55 am
by sivarama2794
Hello admin,
Can you explain a little more on option 3 ''import static com.foo.X.*;'' I didn't get this part.

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

Posted: Tue Aug 09, 2016 4:59 am
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.