r/javahelp • u/Miserable_Bar_5800 • Jan 29 '26
Can I have 2 public classes?
Guys can anyone teach me?
We all know:
public class Main {
Whatever we put after public class it needs to be the file name, like in that it needs Main.java
What if we add two public classes like:
public class Main {
}
public class ootherMain {
}I'm just curious on what happens I think it gets an error or is there a way to actually do that?
0
Upvotes
View all comments
Show parent comment
1
u/onated2 Jan 29 '26
Interesting read.
The private inner class is what i usually do in practice.
The public inner class is what i do in my own projects.
I didn't know about the drawbacks on it though other than the convention. But will look it up.
Thanks