|
Answer» Methods declared with the keyword static as modifier are called static methods or class methods.
There are two types of methods:
- Instance methods : associated with an object and use the instance variables of that object. This is the DEFAULT.
- Static methods : use no instance variables of any object of the class they are defined in. If you DEFINE a method to be static, you will be given a RUDE message by the compiler if you try to access any instance variables. You can access static variables, but except for constants, this is unusual. Static methods typically take all they data from parameters and compute something from those parameters, with no reference to variables. This is typical of methods which do some kind of GENERIC calculation. A good example of this are the many UTILITY methods in the predefined Math class.
Methods declared with the keyword static as modifier are called static methods or class methods. There are two types of methods:
|