+ 1

Why do you omit "public" infront of the class header?

I am currently using a book (along with this tutorial) to learn Java. And my book tells me to do: public class HelloWorld { //lines of codes } instead of class HelloWorld { //lines of codes } like this tutorial teaches. Is this a matter of style? (Does it differ between programmers?) Or is it a matter of syntax that is not necessarily wrong to do so, and it can be done? Please forgive my misuse of terminology, if I misused any. Thank you!

30th Sep 2017, 11:15 AM
Jiho Kim
Jiho Kim - avatar
2 Answers
+ 2
Public means that the class or method can be accessed from another package. If you leave it out only elements of the same package can call it.
30th Sep 2017, 3:59 PM
1of3
1of3 - avatar
+ 2
main() is global function that must require anything outside class if private that mean your class can be accessed by only inside it Well I might be wrong :( cus I don't deeply in class/constructor
30th Sep 2017, 12:46 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar