+ 2
Why do I need "Public" to call the function? Is there anything else I can use instead
The attached code I need "public" , but idk why https://code.sololearn.com/cGxFYW8AC7L0/?ref=app
10 Answers
+ 2
//If you don't make that entry point public then, Your code will not be executed and you get runtime error, see Access modifiers, method etc
+ 4
public is an Access Modifier.
The Java access modifier public means that all code can access the class, field, constructor or method, regardless of where the accessing code is located. The accessing code can be in a different class and different package...
+ 3
Sudarshan Rai đ
is right. The lessons handle that topic and it begins with methods.
Before downvoting please communicate.
He is willi g to help.
+ 3
The main method must be public because it is called from outside it's own class by the JVM and is executed.
Being the entry point of the program, it should be publicly available to be accessed by any other class from any other package.
+ 2
nothing must be public.
Even not constructor.
But how to create in instance if constructor is not public?
+ 2
Additionally there is One entry point at that is main.
A Java prog has classes. which are only definitions and computer must know, where ti begin.
It is looking for main method.
+ 2
Ahh got it, I need a public entry point. Thank you Oma Falk and thank you Sudarshan Rai đ sorry about down vote earlier I read the section on methods, but did not see the part on access modifiers. App took me to a specific page instead of whole lesson
+ 1
Oma Falk I read it, but what I don't understand is why does my second function need to be public if nothing needs access to it ? And why won't default work ?
+ 1
So what needs public Access to the second function ?