About Question enthuware.ocajp.i.v7.2.1079 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.1079 :
import static com.foo.*;
Bad syntax. Package import does not use static keyword.
it´s is correct?
Bad syntax. Package import does not use static keyword.
it´s is correct?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1079 :
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.
The correct option is D.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1079 :
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
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
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1079 :
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: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?
Yes.Deepa wrote: 2.And option (v) is wrong, is it because the static keyword is not there?
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.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.".
HTH,
Paul.
-
- Posts: 33
- Joined: Thu Jul 18, 2013 6:06 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1079 :
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."
"Bad syntax. Package import does not use static keyword."
-
- Posts: 10
- Joined: Sat Jan 24, 2015 8:09 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1079 :
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.
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.
-
- Posts: 4
- Joined: Sat Aug 06, 2016 11:07 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1079 :
Hello admin,
Can you explain a little more on option 3 ''import static com.foo.X.*;'' I didn't get this part.
Can you explain a little more on option 3 ''import static com.foo.X.*;'' I didn't get this part.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1079 :
"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.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests