Newbie: Java Import and compile statement

R

Rachel

Hi,

1. I have 3 files:

c:\folder1\folderA\file1.java // no package statement inside
c:\folder1\folderA\file2.java // no package statement inside
c:\folder1\folderB\file3.java // package folderB;

2. I've compiled file1 & file 2:
c:\folder1\folderA> javac *.java
So, c:\folder1\folderA contains file1.class & file2.class

3. Now, I want to import file1.class & file2.class from c:\folder1\folder11.

Question:
a. What should the import statement be in file3.java?
b. In C:\folder1\folderB, what should the javac statement be for file3.java?

Thanks much,
Rach
 
A

Ahmed Moustafa

Rachel said:
Hi,

1. I have 3 files:

c:\folder1\folderA\file1.java // no package statement inside
c:\folder1\folderA\file2.java // no package statement inside
c:\folder1\folderB\file3.java // package folderB;

2. I've compiled file1 & file 2:
c:\folder1\folderA> javac *.java
So, c:\folder1\folderA contains file1.class & file2.class

3. Now, I want to import file1.class & file2.class from c:\folder1\folder11.

Question:
a. What should the import statement be in file3.java?

import file1;
import file2;
b. In C:\folder1\folderB, what should the javac statement be for file3.java?

javac -classpath
c:\folder1\folderA\file1.class;c:\folder1\folderA\file2.class
 
G

ghl

Ahmed Moustafa said:
import file1;
import file2;

This is incorrect and is now officially wrong. You cannot import from the
unnamed package.
Place all classes in a package from now on. Only use unnamed code for quick
tests and minimal demos.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top