Search code examples
javaclass

How to include existing code/class file when compiling in Java


I am a complete newbie with Java. I use notepad++ to write Java code, and then compile and execute using command line on the Windows Platform

How do I reuse existing code or a class file? For instance, I have written a class in file A.java (with the corresponding compiled class file available) and wish to use that class in B.java. Do I need to specify it in the B.java file (sort of lie c/c++) or using compiler options. What compiler options?


Solution

  • You can use import the A.java class in B.java like this

    import A.java;
    

    By doing like this A class will be available in B class.

    Java Packages Tutorial