How to use class of another java file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpr
    New Member
    • Feb 2008
    • 11

    How to use class of another java file

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

    ->ABC.java

    [CODE=Java]classABC extends JTextField
    {
    ABC(int i)
    {
    super(i);
    ...
    }
    public ABC()
    {
    ...
    }
    }[/CODE]

    ->PQR.java

    [CODE=Java]classPQR
    {
    ABC a1;
    ABC a2;
    ...

    public static main(String[] args)
    {
    ...
    }
    }[/CODE]

    ->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
    Last edited by BigDaddyLH; Feb 4 '08, 06:19 PM. Reason: added code tags
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    It sounds like a classpath issue. If your .java files are in the same directory compile with the command:

    Code:
    javac -classpath . *.java
    the option "-classpath ." tells the compiler to look in the current folder for classes you mention in a .java file.

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      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

      Comment

      Working...