Defining a Private Constructor in private section of the class?

In the exercises of ABAP OOPs book, I have the found following question.
Q. A private instance constructor (instantiation only by the class itself) can be defined in the private section.
True or False
The answer provided in the book is "True". But actually, its not possible to define a constructor in a private or protected section, regardless of the constructor visibility.
Can anyone help me in this question?

from the ABAP help:
The statement METHODS constructor for the declaration of the instance constructor of a class declared with the adition CREATE PRIVATE, can not only be listed in the public, but also in the protected or private visible area. This allows the use of components, which have been declared there, in the interface of the constructor.
the problem might be your SAP system version. I have verified this on Netweaver 7.00.
best regards,
J.N.N

Similar Messages

  • How to call a method in private section of a class in the public section

    Hi Everybody,
    i have written a method(meth1) in the private section of a class(C1).
    it is as follows
    class C1 definition.
    private section.
    methods: meth1 importing im_dt1 like tp1
                                             im_dt2 like tp2
                                             im_dt3 like tp3
                                             im_dt4 like tp4
                               returning value(re_dt1) like tp5.
    endclass.
    i have the final data that has to be displayed in internal table re_dt1.
    now my question is how to call  this method present in private section into public section and display the data present in re_dt1.
    Thanks,
    learning.abap.

    Hi,
    what you need is one public method being called at start-of-selection. Within this the private methods have to be called.
    The question is, why has the method for reading the database tables to be private? If you have only one private method reading all database tables the public method being called at start-of-selection will only consist of a call-method statement.
    This seems to be one call to much.
    The logic for reading the different database tables is hidden inside the class anyway.
    Is there any further logic reading the different database tables?
    Have always all table to be read? If not another approach would be one private method for each database table being called by a public method deciding which table has to be read:
    public section.
    methods get_data returning value(re_Dt1).
    private section.
    methods:
    get_table_a returning value(im_dt1),
    get_table_b returning value(im_dt2),
    get_table_c returning value(im_dt3),
    get_table_d returning value(im_dt4),
    combine_data importing im_dt1
                                    im_dt2
                                    im_dt3
                                    im_dt4
                            returning value(re_dt1).
    *- implementation of public method:
    method get_data.
      data: lt_dt1 ...
               lt_dt2,
               lt_dt3,
               lt_dt4.
    * here decide which tables have to be read:
    lt_dt1 = get_table_a( ).
    lt_dt2 = get_table_b( ).
    lt_dt3 = get_table_c( ).
    lt_dt4 = get_table_d( ).
    re_dt1 = combine_data( i_dt1 = lt_dt1
                                           i_dt2 = lt_dt2
                                           i_dt3 = lt_dt3
                                           i_dt4 = lt_dt4 ).
    endmethod.
    *- implementation of private methods
    method get_table_a.
    endmethod.
    method get_table_b.
    endmethod.
    method get_table_c.
    endmethod.
    method get_table_d.
    endmethod.
    method combine_data.
    endmethod.
    Regards
    Dirk

  • Accessing protected and private data of a class

    Hi friends,
    I have writen a sample code in oops abap but iam facing some problem.
    CLASS MAIN DEFINITION.
        public SECTION.
          DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
          METHODS : PUBLIC.
      ENDCLASS.
      CLASS MAIN IMPLEMENTATION.
         METHOD : PUBLIC.
           WRITE : /5 VAR1.
              VAR1 = 'CHANGED'.
           WRITE : /5 VAR1.
         ENDMETHOD.
      ENDCLASS.
    START-OF-SELECTION.
        DATA :
               O_MAIN TYPE REF TO MAIN.
               CREATE OBJECT O_MAIN.
               CALL METHOD O_MAIN->PUBLIC.
    now its working fine as public methods can be access by all the people where as protected methods can be access by class and subclass so i can inherit the properties of above class and access the protected data.
    where as to access private data , private data can be access by class itself...
    so now how do i access the private data within the class...ie : how do i get the above output when i use a private section instead of public..
                CLASS MAIN DEFINITION.
        private SECTION.
          DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
          METHODS : Private.
      ENDCLASS.
      CLASS MAIN IMPLEMENTATION.
         METHOD : Private.
           WRITE : /5 VAR1.
              VAR1 = 'CHANGED'.
           WRITE : /5 VAR1.
         ENDMETHOD.
      ENDCLASS.
    START-OF-SELECTION.
        DATA :
               O_MAIN TYPE REF TO MAIN.
               CREATE OBJECT O_MAIN.
               CALL METHOD O_MAIN->Private.
    iam getting a error saying you cannot access the private section...
    now private section can be accessed within the class but nt by others...
    to access the private section within the class how should i correct it...
    Regards
    kumar

    HAI,
    Private attributes or methods can be accessed directly by the Object but within the Scope of the Class, but not outside.
    Look at this:
    CLASS MAIN DEFINITION.
    public  SECTION.
    METHODS : Public.
    private SECTION.
    DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
    METHODS : Private.
    ENDCLASS. " END of CLASS DEFINITION
    CLASS MAIN IMPLEMENTATION.
    METHOD : Public.
    CALL METHOD Private.
    ENDMETHOD.
    METHOD : Private.
    WRITE : /5 VAR1.
    VAR1 = 'CHANGED'.
    WRITE : /5 VAR1.
    ENDMETHOD.
    ENDCLASS. " END of CLASS IMPLEMENTATION
    START-OF-SELECTION.
    DATA:  O_MAIN TYPE REF TO MAIN.
    CREATE OBJECT O_MAIN.
    CALL METHOD O_MAIN->Public.
    PS: If there is any better alternative solution please share it .
    Best Regards,
    rama

  • Trying to access a private attribute of a class in the same package

    Hi,
    I have defined a private attribute in a class
    class Sample {
         private String newString = "hello";
    in another class I am trying to access newString attribute using reflection api. It is throwing hte following exception
    java.lang.NoSuchFieldException: value
         at java.lang.Class.getDeclaredField(Unknown Source)
         at refletionpack.mainclass.main(mainclass.java:20)
    any ideas how to do it exactly? Should stringclass.getDeclaredField("value")
    have the field name(newString) as a parameter?
    public class mainclass {
         static Class stringclass = Sample.class;
         static Field stringCharsField = null;
         public static void main(String args[]){
              try{
                   stringCharsField = stringclass.getDeclaredField("value");
                   stringCharsField.setAccessible(true);
                   char[] stringChars = (char[])stringCharsField.get("newString");
                   System.out.println(stringChars);
              }catch(NoSuchFieldException ex){
                   ex.printStackTrace();     
              }catch(IllegalAccessException ex){
                   ex.printStackTrace();     
    }

    Hi,
    to obtain the value of your private attribute you have to change two lines of code. At first you have to tell your class and not the field that private attributes can be accessed by using stringClass.setAccessible(true);After that you have to specify the name of the attribute to obtain which is called newString in your class which results in
    stringCharsField = stringClass.getDeclaredField("newString");For the invocation of the method get(Object) you need an object first that is an instance of the analyzed class by calling Object sample = stringClass.newInstance.
    Then you can retrieve the actual data of the requested field by calling String string = (String) stringCharsField.get(sample);A simpler solution would be when you make your attribute newString static. Then you can omit the necessary object for the retrieval of the attribute data and the line would result in String string = (String) stringCharsField.get(null);.
    For further issues considering reflection you should read the appropriate API.
    Hope it helps.

  • How to change standard class private section code

    Dear experts,
    I need to add new attributes in a standard class as per one OSS note. I took access key to add new attributes. I have a question.
    class name: CL_J_1BEFD
    Attribute: MT_GROUP_C350
    Level: Instance
    Visibility: Private
    Type STANDARD TABLE OF mty_result
    How do i add the instance attribute because i do not want to give the typing and associated type. instead i have to declare data: MT_GROUP_C350 type standard table of mty_result in class builder private section code.
    if you look at the pushbutton between Associated type and Description, for all instance attributes there's a green color lining below the arrow. I want my attribute also to be exactly same.
    Though i have access key, in private section the display<->Change button is disabled.
    Please suggest me how do i add code in private section of a standard class. i have required access key to change the class.
    Thanks,
    Rajesh.

    Hi ,
    Please follow the OSS note 1828074 - Syntax error in LSEPA_MANDATE_UI_LISTF01 / visibility of the method "GET_SELECTED_MANDATES" to change visibility section of a standard class.
    Regards,
    Chetan

  • Not working - student access to private section

    I have a section within aug.edu that was allowing student access and now isn't allowing student access. The debug shows credentials are being passed properly and the time is current. The section is private and uses the credential COMT-3022-A-200808. Would someone please try to troubleshoot this with me?

    *Students needed access to the materials* and the instructor couldn't wait for us to figure out what went wrong. After downloading all the materials, I deleted the section and recreated it. Are you surprised? *The credentials that weren't working before are working just fine now and nothing in the credential process was changed.*
    I've now had to do this with almost half of my active sections this term.
    Message was edited by: makins

  • Accessing a class private variable in the main timeline

    Greetings,
    noob question.
    Here's my main class:
    package
         import flash.external.ExternalInterface;
         public class main
             public function main()
             public function check_DVBViewer()
                 ExternalInterface.call("check_DVBViewer","test");
                 ExternalInterface.addCallback("AutoIT",AutoIT);
             private function AutoIT(my_msg:String)
                     // here we get the callback string
    in the timeline I have a dynamic text box named my_textbox:
    var my_test:main = new main();
    my_test.check_DVBViewer();
    my_textbox.text = ???????
    Basically the class waits for the callback variable (my_msg).
    The problem is: I need to set the dynamic textbox text to my_msg variable.
    How can I access it?
    I know I can access a public var in the timeline with functioname.variable but I can't define a public var inside a function, right?
    Thank you very much for your time.

    dispatch an event when the string is ready:
    package
         import flash.external.ExternalInterface;
         public class main
    private var msg:String;
             public function main()
             public function check_DVBViewer()
                 ExternalInterface.call("check_DVBViewer","test");
                 ExternalInterface.addCallback("AutoIT",AutoIT);
             private function AutoIT(my_msg:String)
                     // here we get the callback string
    msg=my_msg;
    dispatchEvent(new Event("stringready"));
    public function get msgF():String{
    return msg;
    in the timeline I have a dynamic text box named my_textbox:
    var my_test:main = new main();
    my_test.addEventListener("stringready",f);
    my_test.check_DVBViewer();
    function f(e:Event):void{
    my_textbox.text = my_test.msgF;

  • Private method in the comp controller

    HI
    How do ui declare the private method in the componenet controller and declare the parameter one as the node and other as structure, when i click on methods tab it declears the public method with green logo in the implementation view, while i need to define a private method that should reflect with the red like logo in the outline view , when i click implementation tabr
    rgds
    Akeel

    you can write the private method in hte end of the implementation in the other hooks
    //@@begin others
    //write the code here
      //@@end
    Regards,
    Sarbjeet Singh

  • Accessing private method of a class from report

    Hello All,
    I would have to access a private method of a class from a report.
    Is it possible to access private mehod otherthan from its own class and friend classes.
    Please guide on this. If is possible, to access please give some sample code.
    Thanks & Regards,
    Vishnu Priya

    Hi,
    By using the friend concept you can access private attribute or method in outside class.
    Try the following code,
    CLASS C1 DEFINITION DEFERRED.
    CLASS C2 DEFINITION CREATE PRIVATE FRIENDS C1 .
    PRIVATE SECTION.
    DATA : NUM TYPE I VALUE 5.
    METHODS : M2.
    ENDCLASS.
    CLASS C2 IMPLEMENTATION.
    METHOD M2.
    WRITE:/5 'I am method m2 in C2'.
    ENDMETHOD.
    ENDCLASS .
    class c1 definition.
    public section .
    methods : m1.
    endclass.
    class c1 implementation.
    method m1.
    DATA : OREF2 TYPE REF TO C2.
    CREATE OBJECT OREF2.
    WRITE:/5 OREF2->NUM.
    CALL METHOD OREF2->M2.
    ENDMETHOD.
    endclass.
    START-OF-SELECTION.
    DATA : OREF1 TYPE REF TO C1.
    CREATE OBJECT OREF1.
    CALL METHOD OREF1->M1.
    Regards,
    Jeyakumar.A
    Edited by: Jeyakumar Aasai on Apr 14, 2011 11:51 AM

  • Accessing subclass data when parent class is part of private data of another class.

    I am working up an OOP test program and have a problem with data access.
    I have the following classes defined:
    General Test
    General Report
    Specialized Test
    Specialized Report
    The Specialized Test and Specialized Report are subclasses of General Test and General Report, respectively.
    The General Test class contains a General Report class instance as part of it's private data.
    Specialized Test writes a Specialized Report to its parent class data on initialization. The Specialized Report contains additional data items in its private data.
    I have a method for Specialized Test where I first access the Report object stored in the General Test private data, then try to access the private data of the Specialized Report, that should be returned.I get a class mismatch, as the General Test accessor does not know it is returning a Specialized Report.
    Should I simply typecast the returned report to the more specific class before trying to access the subclass data as shown below, even though it will already be the more specific class?
    Thanks,
    Josh

    I don't see your image - maybe it just hasn't finished uploading yet - but if I'm understanding correctly, using To More Specific Class (not Type Cast) is a fine solution here. It's reasonable to use To More Specific Class to get the wire type to match the type of data that you know it will carry when the compiler cannot make that determination for you automatically.

  • How to make Safari on iPad Mini Private and make the display the same as iPhone5 Safari App (iOS7)

    Started when I attempted to turn on private browsing on ipad mini (ios7) as I noticed I was able to do on the iphone5 (ios7) when I clicked the icon on the bottom right to view other tabs. When I press the button on the iPhone the current tab drops back in a cool "3D stack of cards" type of view and there is an option located in the bottom left corner PRIVATE. You can also add a new tab by pressing + in the center bottom.
    The setup/view is completely different in safari app on the ipad mini. To add a new tab there is a + symbol at the TOP and it does not open in the above 3D style mentioned. There is no option for private, nor is there an option in Settings>Safari>Privacy. Tech support unable to assist in a chat. Anyone know how to resolve or have an explanation as to why you cannot? Searching threads and general help online I have read that you are in fact supposed to be able to browse in PRIVATE mode on the ipad mini, and I would also like to have the same visual setup as I view on the iPhone5. 

    The deck of cards is not available on the mini. Private browsing is. Tap the + sign and look in the lower left corner. With the keyboard up it's above the  Q.

  • How to write into a private fiald from the outer world?

    Hello,
    I have just got some strange rerults and want to share them with you.
    I'm writing a bean class. Each field of the bean conforms to a column in a table of the database. The bean is filled with a record of database from database by Entity Factory and is returned to me. I have not seen the sources of the Entity Factory system. The beans are entities that have setter and getters.
    All my colegues use a standard scheme with private field (named as a column in the database) and setter/getter for it. I have deriviated from this scheme creating a virtual property; that is only setter and getter with no private field. And the Entity Factory started crushing! It cannot find the private field anymore to write data from a table into it!
    I had an experiment adding the private field with the final modifier. And what do you think I've got in effect? The entity Factory started complaining that it CANNOT SET A PRIVATE FIELD BECAUSE IT IS MARKED WITH FINAL! Removing the final has solved the problem.
    Can you beleive this story? As the system is Enterprise, I would think that application server would sublass my implementation. But the privates should be inaccessible anyway. I'm going to look into source codes tomorrow.

    As Kayaman says, you can get around the restriction described in the JLS by use of Reflection.
    Consider the following example:
    class SimpleKeyPair {
        private String privateKey = "original"; // private field
    public class ReflectionChecker {
        public static void main(String[] args) throws Exception {
            SimpleKeyPair keyPair = new SimpleKeyPair();
            Class c = keyPair.getClass();
            // get the reflected object
            Field field = c.getDeclaredField("privateKey");
            // set accessible true
            field.setAccessible(true);
            System.out.println("Value of privateKey: " + field.get(keyPair)); // prints "original"
            // modify the member varaible
            field.set(keyPair, "altered");
            System.out.println("Value of privateKey: " + field.get(keyPair)); // prints "altered"
    }

  • Pop up window asking if I want the password remembered won't pop up why I'm not in private browsing and the site is not on the exception list please help

    I can not get the firefox window to ask me if I want my password remembered. I am not in private browsing. The site is not on the exception list in the security box where all the other passwords sites are stored.

    See also;
    *http://kb.mozillazine.org/User_name_and_password_not_remembered
    If disabling autocomplete=off doesn't help then start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Mixing public and private networks on the same switch

    Hello Everyone,
    I know this may get some security engineers in frenzy but wanted to know if there is a safe way to mix public and private networks on the same switch. 
    We have many remote offices that we want to add public wifi and a couple of other services that would be completely outside of our internal network.  Each office has a 3750 with plenty of open ports.  How can I safely create a vlan for public access on these switches which currently have our internal network on.  I have read that people are doing this to save on the cost of purchasing a dedicated switch.  Some people are using access lists and one person mentioned creating a private vlan for the public network.  I looked up private vlan and it seemed bit confusing.
    Is this recommended?  If not what would be the safest way to do this?
    Thanks Everyone

    Disclaimer
    The  Author of this posting offers the information contained within this  posting without consideration and with the reader's understanding that  there's no implied or expressed suitability or fitness for any purpose.  Information provided is for informational purposes only and should not  be construed as rendering professional advice of any kind. Usage of this  posting's information is solely at reader's own risk.
    Liability Disclaimer
    In  no event shall Author be liable for any damages whatsoever (including,  without limitation, damages for loss of use, data or profit) arising out  of the use or inability to use the posting's information even if Author  has been advised of the possibility of such damage.
    Posting
    How "safe" is relative.  If your running just one VLAN on a switch, that's would be the safest (basically the same as mixing traffic on the same wire - separation is done else where).
    If you multiple VLANs on a switch, then you need to determine how likely someone might figure out a way to breach the VLAN barriers.  (This isn't so easy on newer switches.)  If the VLAN isolation is breeched, then you need to examine what does that imply from a security perspective (for example can someone now inject or receive other VLAN traffic).
    For most purposes, I don't see mixing public and private VLANs, alone, on the same switch as much of a risk.  More of a concern is what can be reached on either VLAN and how well it's protected.

  • Starting Firefox in Private mode from the pinned ico in taskbar causes Windows Explorer to crash.

    Starting Firefox in Private mode from the pinned icon in taskbar (right click, choose "New Private Window") causes Windows Explorer to crash almost everytime, but not always. Very odd.
    Didn´t happen with previous versions of Firefox.
    Firefox 22.0, Win 7 Ultimate with all updates applied.

    Hello Paul,
    That's a very odd behavior indeed. All I can think of is that an add-on is confused and makes Firefox crash. The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information. Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!
    Thank you.

Maybe you are looking for