• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"default" access and classpath

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to understand the concept of specifying the fully qualified class name when trying to access a class with default access in one package by its subclass in another package.
So I have the following:

/Users/meera/SCJP/CH1/src/Package1/Accesslevel.java


/Users/meera/SCJP/CH1/src/Package2/TestAccess.java

According to K&B SCJP5, Chapter1 page 14 the only way to access a class with default access in a different package is to do one of the following:
1) Make the class public
2) Use fully qualified name.
But my above code is not compiling. So my fully qualified name is not being recognized. So what is wrong with the name because that is the correct directory. Please help.
Thanks,
Meera


[HENRY: Added Code tags]
[ December 02, 2008: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by meera kanekal:

2) Use fully qualified name.


No, it should be extending the class. In your code, it should be either

OR

[ December 02, 2008: Message edited by: Duc Vo ]
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code doesnt compile because the class AccessLevel has default access level. That means its not visible outside its package. Even if we use fully qualified name it doesnt compile.

And i guess according to K&B(page 14), to make the above code work, one of the following two things can be done:
1. Having those two classes in the same package
2. Making the class AccessLevel public.

Hope its clear!
 
meera kanekal
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srilatha that was precisely my point. I want to access the class using the fully qualified name.
Duc Vo I tried both the things you suggested earlier and it still does not compile. That is why I posted it here hoping to find out how to use fully qualified name for accessing the class. Thank you both for your replies.
Thanks,
Meera
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a class has package visibility, then you cannot access it outside it's package in any ways. Also please post the page number in the book where you found this written that you can access it using the fully qualified class name. It might be an error in the book...
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by meera kanekal:
Srilatha that was precisely my point. I want to access the class using the fully qualified name.
Duc Vo I tried both the things you suggested earlier and it still does not compile. That is why I posted it here hoping to find out how to use fully qualified name for accessing the class. Thank you both for your replies.
Thanks,
Meera


Oops, sorry. Didn't read your post properly. It's right, it wouldn't work. Have to be in the same package.
 
meera kanekal
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankit I have posted the page number in my post but in case you missed it, it is in K&B SCJP5, Chapter1 page 14. I do not think it is an error. They specifically mention that there are 2 solutions to this problem.
1)Make the superclass public in its package
OR
2) Use the fully qualified name.
I was trying to understand how to use the second solution.
Thanks,
Meera
reply
    Bookmark Topic Watch Topic
  • New Topic