This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static Imports :  help Needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static Imports :  help Needed" Watch "Static Imports :  help Needed" New topic

Static Imports : help Needed

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
I came to kwow that only stuff marked static and public is eligible to be used using static import.

Friends please let me know on which page K&B mentioned that public is must. Actually i have finished reading K&B and plannning to take SCJP 5.0 in a day or two but when i am taking the mock exams , i am finding such questions whose theory is not present in K&B (like the above question). This is really bothering me.

Can you guys help me out and moreover please give me some tips about the exam.
Thanks in advance
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Sandeep,

sorry, can't find the page number in the moment. But if the variable has only default visibility, it cannot be seen outside the package.

What cannot be seen cannot be imported.

And thus, variable j has to be marked public.
You didn't asked about protected, but protected also wouldn't do, as then, j would be visible through inheritance only.

Hoping, my use of bold letters is appropriate,

And don't forget the horse shoe for the exam

all events occur in real time
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
No i don't think so making them protected will solve the problem.

They MUST be public.

May be yu can run the example and let me know
[ October 28, 2006: Message edited by: Sandeep Vaid ]
Xavier Juste

Joined: Aug 09, 2005
Posts: 4
I don't think public is a must. You need public in your example because the imports you're doing are from a class which is in another package. Therefore it is normal than to be visible, they have to be public. Nothing to do with the import static statement.

[ October 28, 2006: Message edited by: Xavier Juste ]
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
I still think that my answer is correct.
I think it will be good if you just compile and run the code.
Charith Fernando
Ranch Hand

Joined: Sep 12, 2005
Posts: 67
there is no such rule saying that the static members which you want to import SHOULD be with public access....

that is not necessary.. as long as the member is visible for your class you can static import it...

Charith I Fernando<br />SCJP5, SCWCD, SCBCD, BSc(Hons) IS<br />+94 773 263 222 (mobile)
Charith Fernando
Ranch Hand

Joined: Sep 12, 2005
Posts: 67
take a closer look.. if you want to access the variable J from the 2nd class then you should declare it PUBLIC OR PROTECTED... because the 2nd class is in a different package and if you want access to J then declare it public and access it or else declare it protected and make the 2nd class a sub class of the first.. then also it will work...

default access and private wont suit here due to the reasons given above...
I agree. Here's the link:
subject: Static Imports : help Needed
It's not a secret anymore!