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

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

Moderator: admin

Post Reply
lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

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

Post 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?

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

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

Post by admin »

No, there is no such requirement. You can import just the static members without importing the class.

lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

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

Post by lenalena »

For some reason I was left with impression it was necessary. Thank you for clarifying.

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

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

Post 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.

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

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

Post 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?

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

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

Post by admin »

What happened when you tried it out?

raphaelzintec
Posts: 167
Joined: Sun Apr 21, 2024 10:43 am
Contact:

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

Post 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

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

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

Post by admin »

shows the same in test.
test.png
test.png (8.07 KiB) Viewed 5562 times

Lucvingston
Posts: 1
Joined: Sun Jul 21, 2024 11:21 pm
Contact:

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

Post by Lucvingston »

You could read this trail https://docs.oracle.com/javase/tutorial ... sdecl.html for more details

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests