+ 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!
2 ответов
+ 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.
+ 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