2008 Jul 16 11:05 AM
Hi all,
Can anyone tell me what is the difference between protected components and private components.
It seems like both of them are the same. Sorry, I am confusing.
It is greatly appreciated if someone could explain to me with examples.
Thank you so much.
2008 Jul 16 11:13 AM
Hi,
Are you asking in the Object oriented context? If yes here is the explanation,
Private component
When you declare components in private then, only the objects created for that class can access those components.
Protected component
When you declare components as protected, then the objects created for that class can access those components + the objects declared as friends for this class can also access those components
Eg,
CLASS C1 DEFINITION FRIENDS C2.
PRIVATE SECTION.
DATA A1.
PROTECTED SECTION.
DATA A2
ENDCLASS.
CLASS C2 DEFINITION.
ENDCLASS.
Here objects created for C2 can access data A2 (from C1) but not A1. A1 data is strictly accessible only for objects created for class C1
Hope you get the difference.
//Kothand
2008 Jul 16 11:05 AM
2008 Jul 16 11:08 AM
Hi
Protected Components
All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it.
Private Components
Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.
With Regards
Nikunj Shah
2008 Jul 16 11:13 AM
Hi,
Are you asking in the Object oriented context? If yes here is the explanation,
Private component
When you declare components in private then, only the objects created for that class can access those components.
Protected component
When you declare components as protected, then the objects created for that class can access those components + the objects declared as friends for this class can also access those components
Eg,
CLASS C1 DEFINITION FRIENDS C2.
PRIVATE SECTION.
DATA A1.
PROTECTED SECTION.
DATA A2
ENDCLASS.
CLASS C2 DEFINITION.
ENDCLASS.
Here objects created for C2 can access data A2 (from C1) but not A1. A1 data is strictly accessible only for objects created for class C1
Hope you get the difference.
//Kothand
2008 Jul 17 1:15 AM
Thanks for all the explanation. At least now I have some hints on these.