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: 

private section

Former Member
0 Kudos
189

Why use private section of a local class?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
91

Hi Soman,

we need to declare attributes in a local class with in a private section

to avoid access by others class means only objects of that class can access it.

For Ex. In a company some documents are private and confidencial only employee can see it. same way only objects of that calss can acess private objects.

if you are going with inheritance we need decalre the attributes in a public section so that inherited class can access it. you can also use Protedted class wich can be access by inherited class

Kindly Award Points If You Find The Reply Helpful.

Cheers,

Chaitanya.

7 REPLIES 7

Former Member
0 Kudos
91

Hi

To PROTECT the data to acess the data from out side classes

http://help.sap.com/saphelp_nw70/helpdata/en/c3/225b6554f411d194a60000e8353423/content.htm

matt
Active Contributor
0 Kudos
91

Naresh is right, but perhaps you think it a little odd to have a private section in a local class, seeing as the local class can't be accessed outside the program anyway. The reason for doing it, is data encapsulation. By being specific about what data can be used under what circumstances, you have a better defined data model, and so you reduce the scope for error.

While you may be well aware of how your variables and methods should be used, the programmer who maintains your program in two years time may not be. By using good encapsulation, you prevent him from making some errors. If an attribute is private, he can't access it outside the class. If he decides to make it public, he can of course just change the class - but he has to do it deliberately.

Defining variables and methods with the correct scope is vital to writing good programs.

matt

Former Member
0 Kudos
92

Hi Soman,

we need to declare attributes in a local class with in a private section

to avoid access by others class means only objects of that class can access it.

For Ex. In a company some documents are private and confidencial only employee can see it. same way only objects of that calss can acess private objects.

if you are going with inheritance we need decalre the attributes in a public section so that inherited class can access it. you can also use Protedted class wich can be access by inherited class

Kindly Award Points If You Find The Reply Helpful.

Cheers,

Chaitanya.

matt
Active Contributor
0 Kudos
91

>

> Hi Soman,

>

...

>

> if you are going with inheritance we need decalre the attributes in a public section so that inherited class can access it. you can also use Protedted class wich can be access by inherited class

>

If you declare attributes that are to be inherited you should use protected. You should only use public if access is required outside of the class. Public access is always the LAST choice, not the first.

matt

Former Member
0 Kudos
91

Hi

To secre the data with in the class and not to access from out side the class

The private components of the superclass are not visible though they exist in the subclass. You can declare private components in a subclass that have the same names as private components of the superclass. It is seen that each class works with its own private components. The another point that we note is that methods which a subclass inherits from a superclass use the private attributes of the superclass and not any private components of the subclass with the same names.

matt
Active Contributor
0 Kudos
91

Why do you answer this thread twice? Didn't you notice your original answer?

matt

0 Kudos
91

he is not closing thread so i am giving him a clear information about this