aspose file tools*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static Imports :  help Needed" Watch "Static Imports :  help Needed" New topic
Author

Static Imports : help Needed

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
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,
Bu.

---
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: 390
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
Greenhorn

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.

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

Joined: Feb 27, 2006
Posts: 390
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Static Imports : help Needed