does the class containing the main method need to be declared public? is it necessary to do so? also i would like to know if we can declare more than 1 class as public in a java file? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

does the class containing the main method need to be declared public? is it necessary to do so? also i would like to know if we can declare more than 1 class as public in a java file?

26th Sep 2016, 9:46 PM
ABHISHEK SHARMA
ABHISHEK SHARMA - avatar
4 Answers
+ 3
Yes, main needs to be public, and yes, you can declare more than one public method.
26th Sep 2016, 10:09 PM
Zen
Zen - avatar
+ 1
no and yes
27th Sep 2016, 5:41 AM
Vivek Anand
0
yes & yes
5th Oct 2016, 10:51 PM
Uwem Neku
Uwem Neku - avatar
0
yes main should be in public class and we can have any number of classes as public
22nd Oct 2016, 12:14 PM
Bindu Bindudc
Bindu Bindudc - avatar