Is it necessary to have a public class in every Java program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it necessary to have a public class in every Java program?

I learned that, we must have to give the program name as same as the public class's name which we will use in the program. So, there will be multiple classes in a program as per as my requirement. So, is it necessary to put a public class in any Java program to run the program?

19th Jun 2018, 3:12 PM
Surajit
Surajit - avatar
2 Answers
+ 6
The main method is the entry point of your program which is inside a class.
19th Jun 2018, 4:04 PM
D_Stark
D_Stark - avatar
0
See in your Java program you must have to save your file name as your public class's name. So, for your programs the public class acts like the entry point. You can say that, it is mandatory!
5th Sep 2018, 4:43 AM
Surajit
Surajit - avatar