What is the difference in attributes defined in the public versus private section of a class?
Answer Posted / Eram Khan
"The primary difference between attributes defined in the public and private sections of a class in SAP ABAP (Object Oriented) lies in their visibility. Public attributes (DATA or FIELDS defined outside any SECTION) can be accessed from anywhere, including other classes. On the other hand, private attributes (DATA or FIELDS defined within a section such as PRIVATE SECTION, PROTECTED SECTION, or HIDDEN SECTION) are only accessible within their defining class and its subclasses. Here's an example:nn```abapnCLASS zcl_example DEFINITION.n PUBLIC SECTION.n CLASS-DATA: gt_public TYPE STANDARD TABLE,n gv_private TYPE i.nENDCLASSnCLASS zcl_example IMPLEMENTATION.n METHOD method1.n DATA: lv_local TYPE i.n APPEND lv_local TO gt_public.n ASSIGN gv_private TO lv_local.n ENDMETHODn``` In the example above, gt_public is a public attribute and gv_private is a private attribute. "
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
No New Questions to Answer in this Category !! You can
Post New Questions
Answer Questions in Different Category