Application Development and Automation 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: 
Read only

can static methods /attributes be called from instance?

Former Member
0 Likes
693

CLASS lcl_course DEFINITION.

PUBLIC SECTION.

METHODS: get_course_name IMPORTING im_name type string.

CLASS-METHODS: list_prices_and_discounts.

ENDCLASS.

CLASS lcl_course IMPLEMENTATION.

METHOD get_course_name.

ENDMETHOD.

METHOD list_prices_and_discounts.

ENDMETHOD.

ENDCLASS.

Data: course1 type ref to lcl_course,

course2 type ref to lcl_course.

Start-of-selection.

Create object course1.

call method course1->list_prices_and_discounts(). """""""" would this call be considered right??

All i want to know is , can we call the static attributes/methods of a class from the instance??...

Is it required that we should only call static attributes with Class names in our program??

should i only use lcl_course=>list_prices_and_discounts().

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
664

you still have any doubt..?

6 REPLIES 6
Read only

Former Member
0 Likes
665

you still have any doubt..?

Read only

0 Likes
664

yes plzz tell me if its rite

Read only

0 Likes
664

it is possible in case of static attr/methods like instance variables/methods we can call using instance.

Read only

matt
Active Contributor
0 Likes
664

>

> CLASS lcl_course DEFINITION.

> PUBLIC SECTION.

> METHODS: get_course_name IMPORTING im_name type string.

> CLASS-METHODS: list_prices_and_discounts.

> ENDCLASS.

>

> CLASS lcl_course IMPLEMENTATION.

> METHOD get_course_name.

> ENDMETHOD.

> METHOD list_prices_and_discounts.

> ENDMETHOD.

> ENDCLASS.

>

> Data: course1 type ref to lcl_course,

> course2 type ref to lcl_course.

> Start-of-selection.

> Create object course1.

>

> call method course1->list_prices_and_discounts(). """""""" would this call be considered right??

>

>

> All i want to know is , can we call the static attributes/methods of a class from the instance??...

>

> Is it required that we should only call static attributes with Class names in our program??

>

> should i only use lcl_course=>list_prices_and_discounts().

Why don't you simply try it? If list_prices_and_discounts() on it's own works, then fine. If not then you know you must use the class name.

As a matter of good programming style, I always use the class name, even in static methods, as then it is clear what is going on, that the method or attribute is static. Similarly in instance methods, I always use me-> when referencing other instance methods or attributes,

I reaaly don't understand why this kind of question is asked. Are you afraid that if you use the wrong syntax you'll break the system or something?

Read only

Former Member
0 Likes
664

Matt,

When i posted that time name is some thing , now it become XYZ. interesting.

Read only

Former Member
0 Likes
664

Thanx for the answers..