+ 2
I don't understand when to use public, private and static words...
3 Answers
+ 7
public: Any other class can access that method
private: only that own class can access that method
+ 4
we use static with a method when we don't want to create an object of that. e.g we use
public static void main -
in case of main method and we never creates an object of main method..!
+ 2
public : given element is accessible to every class in the package
private : given element is only accessible inside the parent class
fun like getters & setters are used to use them
static : given element is unique for the whole class ( all instances )
i.e. only one copy of the element is created for whole class and all instances