Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Imports : help Needed

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Fernando
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic