Computer engineer Computer engineer - 2 months ago 7
Java Question

eclipse failing to print the output becouse of some error

I'm starting to learn java. But even when I did everything that the guy in the tutorial said, I got this error.
This is my code:

class code{
public static void main(String args[]) {
System.out.println("coding...");
}
}


the output is this :

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at code.code.main(code.java:2)


Hope u ll help me sort this out thanks.

Answer

You need to declare a package at beginning of the file, like this:

package code;

And your full source code should be with a public class, like this: Try to make your class public and try again

public  class code{
    public static void main(String args[])
   {
      System.out.println("coding...");
   }
}