I don't understand when to use public, private and static words... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I don't understand when to use public, private and static words...

23rd Feb 2016, 2:50 AM
Maria Rosaria Amabile
Maria Rosaria Amabile - avatar
3 Answers
+ 7
public: Any other class can access that method private: only that own class can access that method
24th Feb 2016, 11:32 PM
Jake
Jake - avatar
+ 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..!
7th May 2016, 3:26 PM
Ateeb
Ateeb - avatar
+ 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
4th Sep 2016, 8:57 AM
Harsh