• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

class file....

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
How can I access a class file which is in the same folder as the main java file to which i want to call the class file.
Like ,in the folder c:/anand i have a.class and b.java files,now i want t access the methods in the a.class file in the b.java file .How do i do that?

Anand
 
Sheriff
Posts: 17110
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming the a.class is at least friendly, it depends on how it was packaged.
If a.class was compiled with a package statement, then you need to put the same package statement in b.java or import a.class:
import somepkg.a;
If a.class was compiled without a package statement, it is included in the "default" no-name package. In this case, the easiest would be to compile b.java with no package statement so that it too belongs to the no-name package. This way, a.class is visible in b.java, no import statement is needed.
Also, check CLASSPATH and make sure that your package statements, if any, are consistent with it.
These are just some of the usual scenarios--YMMV.
HTH
J. Lacar
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anand,


Please read the JavaRanch policy on user names at http://www.javaranch.com/name.jsp, and re-register using an ID with a complete (and separate) first and last name, each with more than 1 letter.
Thanks,
Cindy

 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic