Application Development 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: 

protected components and private components

Former Member
0 Kudos

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

Former Member
0 Kudos

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

matt
Active Contributor
0 Kudos

Have you tried searching this forum?

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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