10-07-2007 5:32 PM
can anybody explain what is the main difference between static and instance components of a class in all aspects.
10-07-2007 8:41 PM
Hello Sandeep
There are two major differences:
1. Static components are "always" there meaning it is not required to create an instance of the class. Example: public static attribute CL_GUI_CFW=>FALSE.
2. Instance attributes are not visible in static method (whereas static attributes are visible in instance methods). Example: If you try to reference ME within a static class you get a syntax error.
Regards
Uwe
10-07-2007 8:41 PM
Hello Sandeep
There are two major differences:
1. Static components are "always" there meaning it is not required to create an instance of the class. Example: public static attribute CL_GUI_CFW=>FALSE.
2. Instance attributes are not visible in static method (whereas static attributes are visible in instance methods). Example: If you try to reference ME within a static class you get a syntax error.
Regards
Uwe
10-08-2007 1:25 AM
Hi Sandy,
"instance" components need to be instantiated. Static components do not.
By example, take a static method of class myclass called mymethod. To call this method you just need to do something like this
call method myclass=>mymethod
It is essentally the same as a function module you could call like this.
call function 'myfunction'
Instance components require the class to be instantiated and copies of the components are created for each instantiated class. So you could instantiate the same class twice and the components of each class would be very separate.
Instantiation can happen a few different ways, but simplistically you would have to do something like this.
data myinstance type ref to myclass.
create object myinstance.
call method myinstance1->mymethod
Cheers
Graham Robbo