Page 1 of 1

About Question enthuware.ocajp.i.v8.2.976 :

Posted: Wed Mar 08, 2017 4:18 pm
by lenalena
Wouldn't you need to import the class itself using a regular (non static) import first (import x.y.* or import x.y.SM), before you can import static SM's static members?

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Wed Mar 08, 2017 9:35 pm
by admin
No, there is no such requirement. You can import just the static members without importing the class.

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Wed Mar 08, 2017 11:41 pm
by lenalena
For some reason I was left with impression it was necessary. Thank you for clarifying.

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Thu Mar 09, 2017 12:27 am
by admin
But remember that if you don't import the class, you cannot access the class without package name. For example, if you have only - import static java.util.Calendar.*;

System.out.println(ALL_STYLES); //This will work fine because static members of Calendar have been made known to the compiler.
System.out.println(Calendar.ALL_STYLES); //This will NOT compile because the name Calendar is still unknown to the compiler.

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Tue Oct 03, 2017 6:48 pm
by dvc1190
What if there were two foo methods in SM.java? For instance, a public static void foo(int I) in addition to the no arg one. Which method is imported?

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Wed Oct 04, 2017 12:13 am
by admin
What happened when you tried it out?

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Sun Aug 11, 2024 11:49 am
by raphaelzintec
yo, all imports, packages, and some other stuff i see egyptians hyeroglyphes... you should test your self

what i'm trying to say is that during test i have seen this:
option 2: import static x.y.SI;
option 3: import static x.y.SM.;
option 4: import static x.y.SM.foo;

now after i finished test i see this:
option 2: import static x.y.SM;
option 3: import static x.y.SM.foo;
option 4: import static x.y.SM.foo();

so ofc i selected option 4 lol it hasnt show me any () during test

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Sun Aug 11, 2024 12:51 pm
by admin
shows the same in test.
test.png
test.png (8.07 KiB) Viewed 5567 times

Re: About Question enthuware.ocajp.i.v8.2.976 :

Posted: Sun Aug 11, 2024 10:04 pm
by Lucvingston
You could read this trail https://docs.oracle.com/javase/tutorial ... sdecl.html for more details