Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

protected components and private components

Former Member
0 Likes
932

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
716

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

4 REPLIES 4
Read only

matt
Active Contributor
0 Likes
716

Have you tried searching this forum?

Read only

Former Member
0 Likes
716

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

Read only

Former Member
0 Likes
717

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

Read only

0 Likes
716

Thanks for all the explanation. At least now I have some hints on these.