‎2021 Oct 14 8:17 AM
What is the difference between static and instance method?
When and why instance method is used ?
‎2021 Oct 14 8:24 AM
Dear Gakuto,
the terms "instance" and "static" are general terms from the Object Orientation (OO) programming paradigm.
Imagine, you are a car manufacturer. You would want to track the mileage per car and also the number of cars produced in total. For this scenario, we specify the class "Car". In this class, we specify a static attribute "NumberOfCarsProduced" and a static method "IncreaseNumberOfCarsProduced". Whenever we create a new instance of the class "Car", we increase the number of cars produced in total. The number of cars produced in total is of course static. For the instance, we specify an instance attribute "Mileage" and an instance method "IncreaseMileage". Whenever we drive with a car instance, we increase the mileage. The mileage of a car instance is an instance attribute.
With kind regards,
Michael
‎2021 Oct 14 8:24 AM
Dear Gakuto,
the terms "instance" and "static" are general terms from the Object Orientation (OO) programming paradigm.
Imagine, you are a car manufacturer. You would want to track the mileage per car and also the number of cars produced in total. For this scenario, we specify the class "Car". In this class, we specify a static attribute "NumberOfCarsProduced" and a static method "IncreaseNumberOfCarsProduced". Whenever we create a new instance of the class "Car", we increase the number of cars produced in total. The number of cars produced in total is of course static. For the instance, we specify an instance attribute "Mileage" and an instance method "IncreaseMileage". Whenever we drive with a car instance, we increase the mileage. The mileage of a car instance is an instance attribute.
With kind regards,
Michael
‎2021 Oct 14 9:43 AM
‎2021 Oct 14 9:54 AM
Hi aiueo
The main difference between the two is that instance method can be called using object reference only and hence is dependent on object while the static method can be called irrespective of the object for a class, it can be called using class name and hence is not dependent on object.
Static method can access only static attributes while instance method can access static as well as instance attributes. You can declare a static method using 'METHODS' keyword and instance method can be declared using keyword 'CLASS-METHODS'.
‎2021 Oct 17 6:21 PM
‎2021 Oct 18 9:45 AM
Static Methods: these methods can be called without creating an object for the class. these methods can be directly called using the class name like
cl_gui_frontend_services=>gui_download().
Instance Methods: These methods can be only called using the object of the class.