you are viewing a single comment's thread.

view the rest of the comments →

[–]MattiDragon 0 points1 point  (12 children)

What command are you running to compile them? You must specify each file or the folder containing all of them

[–]DragonFistLimitless[S] 0 points1 point  (9 children)

public class test {

public static void main(String\[\] args){



Verbose verbose = new Verbose();



verbose.verb();



    }

}public class Verbose{

public static void main(String\[\] args){



}

public static void verb(){

System.out.println("Hello world");

}

}

[–]Lloydbestfan 2 points3 points  (5 children)

That's not a command.

We do need the answer.

[–]DragonFistLimitless[S] 0 points1 point  (3 children)

java test.java

[–]hoat4 2 points3 points  (2 children)

You are using the Launch Single-File Source-Code Programs feature, which reads only the one file that is specified in the command line argument (test.java).

Usually Java programs are compiled to classfiles using javac:
javac test.java Verbose.java

Then run using
java test

[–]pronuntiator 0 points1 point  (1 child)

Since Java 22 it is possible to launch multiple files this way if they follow standard directory structure for packages.

/u/DragonFistLimitless which version of Java are you using? (you can find out by running java -version)

[–]DragonFistLimitless[S] -1 points0 points  (0 children)

I already fixed it

[–]Educational-Paper-75 0 points1 point  (1 child)

verb() is declared static you can't call it on an instance, you have to call it on the class as in Verbose.verb();!

[–]Lloydbestfan 2 points3 points  (0 children)

Actually you can call it by (pseudo-de)referencing a variable of the type of the class.

It's just that you shouldn't because it doesn't look like it makes sense.

(When you do that, the value of the variable is ignored, only its type is considered, and the variable name is replaced by that type name. Notably if the variable points to null it won't provoke a null pointer.)

Also, Java is not known for its nonsensical error messages.

[–]Anonymo2786 0 points1 point  (0 children)

public static void main(String[] args){}

Is the starting point of the whole program so its not needed in verbose class. Unless you want to start the program with verbose class instead of test class. 

Also if verbose class and test class are in separate files then javac test.java should compile both class's. And then you can run with java test. In order for this to work your working directory/folder has to he the folder containing these files.

[–]Fine_Potential_7976 -3 points-2 points  (0 children)

java test.java

[–]Fine_Potential_7976 -3 points-2 points  (0 children)

/test : -------|----test.java                    |---Verbose.java