What's the difference between public class Main and class Main?

Nate Sedler :

I'm taking AP Computer Science this year and my teacher says to use public class Main opposed to just class Main. When we asked her why not class Main she said that's just how AP Computer Science does it and didn't elaborate on it at all.

ItFreak :

It is about how your class can be accessed. Using only class Main, the class can only be accessed from inside her package and the class self. Using public class Main, the class can be accessed from anywhere.
You can read more about modifiers at the javadoc:
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=90660&siteId=1
Recommended