• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

packages

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following directories:


The code is :
for test.java:


for Beverage.java:


Why wouldn't this code compile ?
Are classes Beverage and test concidered to be in the same package or not ?

thank you.
regards,
 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it to compile that was a classpath mistake.

so does this answer my question: 2 classes are concidered to be in the same package as long as they have to same root.

for example
com.foo.bar.too.me.class
and com.you.class are in the same package and hence if one is declared with no access modifiers the other one can use it right ?

thanks!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you forgot the access modifier.

both classes have default access, so thy only can accessed by classes in the same package, but they are in different packages "Cert" and Cert.Kaka.

class test cannot extend Beverage bcause it cannot see the class (test is not in the same package as Beverage.)

regards

Holger
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java Modifier Summary
 
aymane chetibi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Wise & Holger,

Thank you for your answers: I did not forget the access modifier and I know what them mean.

What I want to know is When 2 classes are concidered to be in the same package. (when they have the same root ? or when they are in the exact same subdirectory )

I am pretty sure the answer was the first one since the code compiles correctly but I just wanted to make sure.

For Holger, the code compiles correcty. The classes do see each other.

thank you.
regards,
 
reply
    Bookmark Topic Watch Topic
  • New Topic