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?

10th Jan 2017, 5:32 PM
Kousik Mitra
Kousik Mitra - avatar
5 ответов
+ 3
Just create the class within the main, for example after the public static void main(String[ ] args) { public class ExampleClass{......
10th Jan 2017, 5:47 PM
seamiki
seamiki - avatar
+ 2
yes we can but the class name must differ from the name of the program.
10th Jan 2017, 5:38 PM
seamiki
seamiki - avatar
+ 2
how? please give a short example
10th Jan 2017, 5:39 PM
Kousik Mitra
Kousik Mitra - avatar
+ 1
It depends if its a public class
10th Jan 2017, 9:39 PM
shi_qui
shi_qui - avatar
+ 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.
11th Jan 2017, 6:27 PM
Rishav Chudal
Rishav Chudal - avatar