0
Can I create a new class in the same java file?
here they showing we can create a class in another java file and creating an object in the main file. but I am asking can we create the class in the same main java file?
5 ответов
+ 3
Just create the class within the main, for example after the
public static void main(String[ ] args) {
public class ExampleClass{......
+ 2
yes we can but the class name must differ from the name of the program.
+ 2
how? please give a short example
+ 1
It depends if its a public class
+ 1
Yes you can create multiple classes within a same java file but the problem is about the cleanliness in the code.
You should manage your code & make it effective and clean.