A private or public operator is an access modifier; a private access modifier makes it inaccessible to external objects, where an open access modifier makes it available to external objects. usage example:
Say we have a class:
class myClass{ public void test(){
Create an instance of this class:
myClass mClass=new myClass();
To access this member function you have to go:
mClass.test();
If he had a private access modifier, you would get a compilation error stating that this is not available.
And just for the sake of knowledge, in order to access an element without creating an instance of the class, you also need to make this element static, for example:
class myClass{ public static void test(){
So, to access it now, just do:
myClass.test();
(Note that any members accessed in a static member must also be static)
Anomaly Feb 19 '14 at 13:35 2014-02-19 13:35
source share