cancel
Showing results for 
Search instead for 
Did you mean: 

private class

ravi_kumar221
Participant
0 Kudos
144

hi help me soon i need to create one private class in my application  give me some  example

View Entire Topic
Former Member
0 Kudos

Hi,

I am not sure what sort of example you want.

To create a private class the only thing you have to do is:

Go to SE24,

Create a class

And in the popup, select 'Private' in Instantiation.

ravi_kumar221
Participant
0 Kudos

hi  how will i use private class in my program  pleas help me

Former Member

In the private class say ( ZCL_TEST) , create a static method say CREATE_OBJECT. In this method create an object of type ref to ZCL_TEST and set it as an exporting parameter of the method.

Now in your program call this method like ZCL_TEST=>CREATE_OBJECT and you will get the reference object from this method.

Now you can call any instance methods of this class using this reference.

ravi_kumar221
Participant
0 Kudos

Hi your ans is very helpful for me but can u explain        why we need private        ClASS

Former Member
0 Kudos

Hi,

One very simple scenario for creating a Private class is when you dont want that instances of the class can be created outside the class.

The creation of a Private class is generally used along with 'FINAL' to make the class as singleton. In this case, the class can be instantiated only once.

ravi_kumar221
Participant
0 Kudos

what is singleton  class

Former Member
0 Kudos

Singleton Class is a class that can be instantiated only once.

You can search on google. You will get better answers.