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: 

Difference between Static & Instance Attribute of a Class

Former Member
0 Kudos

Hi experts,

If I may ask what is the difference between static & instance of a class?

Example.

PRIVATE SECTION.

DATA: name TYPE string,

planetype TYPE saplane-planetype.

CLASS-DATA: n_o_airplanes TYPE i.

2 REPLIES 2

Former Member
0 Kudos

Hi,

INSTANCE variables:

Things that an object knows about itself are called instance variables.

They represent an object’s state( the data ), and can have unique values for each object of that type.

STATIC variables:

When a member is declared static, it can be accessed before any objects of is class are created, and without reference to any object. You can declare both methods and variables static.

STATIC means they are common to all Instances of the Class, where as INSTANCE variables are pertains to a Particular object of that class.

All the Instances of the class share the STATIC varaibles but in case of INSTANCE variables each object have its own copy.

Regards,

Anji

Former Member
0 Kudos

Hi marc,

1. normally instance concept is used.

2. It means, that,

the program has to create the object (of the type of that class),

and only after creating that object in memory,

it can access that paritcular attribute.

3. Otherwise,

4. If it is static,

then simply by using the classname (without creating the object in memory),

we can use the attribute.

regards,

amit m.