0

This is my code in one file:

package AI;

public class Class1 {
    public static void main1() {
        System.out.println("Hello");
    }
}

And the other file:

package AI;

public class partsOfSpeech {
    public static void main(String args[]) {
        Class1 firstInstance = new Class1();
        firstInstance.main1();
    }
}

How do I compile these files, so that I don't get an error that says it can't find Class1? And how do I run them once they are compiled?

Vityou
  • 152
  • 1
  • 11

2 Answers2

0

just open package AI in commend line and

D:\AI>javac partsOfSpeech.java Class1.java

both class compile--- For Run the class in Commend line

D:/>java AI.partsOfSpeech 

your class run

0

1) Go one directory above AI (e.g. D:\Study\Examples\src)

2) javac -d . AI/Class1.java

3) javac -d . AI/partsOfSpeech.java

4) java AI.partsOfSpeech

output:

Hello

Directory structure:

In my system, AI directory is under src directory.

Directory of D:\Study\Examples\src\AI

11/15/2015  11:06 PM    <DIR>          .
11/15/2015  11:06 PM    <DIR>          ..
11/15/2015  11:06 PM               390 Class1.class
11/15/2015  10:58 PM               118 Class1.java
11/15/2015  11:06 PM               333 partsOfSpeech.class
11/15/2015  10:59 PM               177 partsOfSpeech.java
               4 File(s)          1,018 bytes
               2 Dir(s)  236,298,690,560 bytes free

D:\Study\Examples\src>
Ravindra babu
  • 37,698
  • 11
  • 250
  • 211