protected, public and private
-
I just got a lil confussed here. I want to access a variable using the object of the class.
classXYZ objectname= new classXYZ(); objectname.variablename=100;
so which access specifier is best for variablename. Thanks. -
I just got a lil confussed here. I want to access a variable using the object of the class.
classXYZ objectname= new classXYZ(); objectname.variablename=100;
so which access specifier is best for variablename. Thanks.If that code is outside classXYZ, you have no choice, it must be declared public. Regards Senthil Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
I just got a lil confussed here. I want to access a variable using the object of the class.
classXYZ objectname= new classXYZ(); objectname.variablename=100;
so which access specifier is best for variablename. Thanks.public
: Accessible outside the class.protected
: Accessible to instances of the class, and to any classes derived from it.private
: Accessible only by the class itself.
Software Zen:
delete this;
-
I just got a lil confussed here. I want to access a variable using the object of the class.
classXYZ objectname= new classXYZ(); objectname.variablename=100;
so which access specifier is best for variablename. Thanks.karmendra_js wrote:
I want to access a variable using the object of the class.
Accessing Class Variable outside class is not part of Good design.. always create
Get
andput
function to access variable outside the class."Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV