About Question enthuware.ocajp.i.v8.2.976 :
Moderator: admin
-
- Posts: 56
- Joined: Tue Feb 21, 2017 4:24 pm
- Contact:
About Question enthuware.ocajp.i.v8.2.976 :
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?
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
No, there is no such requirement. You can import just the static members without importing the class.
-
- Posts: 56
- Joined: Tue Feb 21, 2017 4:24 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
For some reason I was left with impression it was necessary. Thank you for clarifying.
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
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.
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.
-
- Posts: 15
- Joined: Tue Feb 25, 2014 3:14 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
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?
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
What happened when you tried it out?
-
- Posts: 167
- Joined: Sun Apr 21, 2024 10:43 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
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
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
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
shows the same in test.
-
- Posts: 1
- Joined: Sun Jul 21, 2024 11:21 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.976 :
You could read this trail https://docs.oracle.com/javase/tutorial ... sdecl.html for more details
Who is online
Users browsing this forum: No registered users and 14 guests