0

This is my first Java piece of code.

I have AnotherClass defined in anotherClass.java in this fiddle:

Although both classes are in the same file path, the HelloWorld class is unable to access AnotherClass.

What have I done wrong?

I reproduce the code in the fiddle below:

HelloWorld.java:

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
        AnotherClass c = new AnotherClass();
     }
}

anotherClass.java:

public class AnotherClass {
    public AnotherClass() {
        //do nothing
    }
}
Old Geezer
  • 14,854
  • 31
  • 111
  • 198
  • 5
    `anotherClass` != `AnotherClass`. – Tunaki Mar 05 '17 at 17:55
  • 1
    And `Classe` != `Class`. – JB Nizet Mar 05 '17 at 17:55
  • Make the first class public and then the other classes, below it, not public. http://stackoverflow.com/questions/2336692/java-multiple-class-declarations-in-one-file – Chris Sharp Mar 05 '17 at 17:58
  • 1
    Also, don't use online compilers, or at least don't use the one provided by tutorialspoint. It is hiding the real error, which is `class AnotherClass is public, should be declared in a file named AnotherClass.java` – BackSlash Mar 05 '17 at 17:58

0 Answers0