• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

regarding accessibility

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If
I want to use a class with in same package
i can access it with no problem
but i give the package declaration in my current class which wants to access some other class then it says other class not found .Even if I try to give same package declaration in other class compiler gives same error
Can anyone give some suggwstion of how to do it?
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Gaurav.
I store my source (*.java) files in directory C:\Java. Therefore, I have added "C:\Java" to my CLASSPATH variable. If I want to create one Java package called "first", and another one called "second", then I need to create folders C:\Java\first and C:\Java\second.
This following code, I saved as C:\Java\first\Book.java. Notice the package statement:

This next code, I saved as C:\Java\second\Library.java. Notice its package statement, and import statement, since it references Book, a class from another package:

To compile Book.java, I go to a command prompt and change the directory to C:\Java, then type
C:\Java>javac first\Book.java
And to compile Library.java,
C:\Java>javac second\Library.java
To run Library, I type
C:\Java>java second.Library
and get back
Pages: 654
To be able to directly invoke "java" and "javac", I had added C:\jdk1.3\bin to my PATH variable. This all assumes you are running Windows on your machine, which I don't know to be true.
Perhaps you forgot to use the import statement? Note, the import statement is not needed in Library.java if you specify the full path when you reference classes from other packages:

If I remove the "first" qualifier from this example, the compiler complains, saying that it "cannot resolve symbol," pointing to class "Book". Is this the kind of error you are getting, Gaurav?
Art
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnkx a ton for clearing my concepts
u r great
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic