By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,677 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,677 IT Pros & Developers. It's quick & easy.

How to use class of another java file

P: 11
I have 2 classes saved as 2 different java files.(eg- class ABC.java & PQR.java)

->ABC.java

Expand|Select|Wrap|Line Numbers
  1. classABC extends JTextField
  2. {
  3.     ABC(int i)
  4.     {
  5.     super(i);
  6.     ...
  7.     }
  8.     public ABC()
  9.     {
  10.     ...
  11.     }
  12. }
->PQR.java

Expand|Select|Wrap|Line Numbers
  1. classPQR
  2. {
  3.     ABC a1;
  4.     ABC a2;
  5.      ...
  6.  
  7.    public static main(String[] args)
  8.     {
  9.     ...
  10.     }
  11. }
->Now problem is that HOW CAN I MAKE a1& a2 as objects of class ABC? While compling PQR doesn't find class ABC as it is in another java file. So How can i use a class From ABC. java file in PQR.java
Feb 4 '08 #1
Share this Question
Share on Google+
2 Replies


BigDaddyLH
Expert 100+
P: 1,216
It sounds like a classpath issue. If your .java files are in the same directory compile with the command:

Expand|Select|Wrap|Line Numbers
  1. javac -classpath . *.java
the option "-classpath ." tells the compiler to look in the current folder for classes you mention in a .java file.
Feb 4 '08 #2

BigDaddyLH
Expert 100+
P: 1,216
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Feb 4 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.