- In some languages (e.g. C++, Java), class methods are synonymous with static methods (see section below), which are called with a known class name at compile-time.
thiscannot be used in static methods.
- In some other languages (e.g. Smalltalk, Ruby, Objective-C), class methods are methods that are called on a class object, which can be computed at runtime, there being no difference between calling a method on a regular object or a class object; thus both instance and class methods are resolved dynamically, and there are no "static" methods. Notably, in these class methods,
thisrefers to the class object.
- Some languages have both. For example, in Python, one can create class methods and static methods using the
staticmethoddecorators, respectively. The former has access to
this(i.e. the instance object, conventionally known as
self), while the latter does not.
Read more about this topic: Method (computer Programming)
Other articles related to "methods, class, class methods":
... Like Smalltalk, in Objective-C, the instance variables and methods are defined by an object's class ... A class is an object, hence it is an instance of a metaclass ... Like Smalltalk, in Objective-C, class methods are simply methods called on the class object, hence a class's class methods must be defined as instance methods in its ...
... Class methods are methods that are called on a class (compare this to class instance methods, or object methods) ... C++, Java), class methods are synonymous with static methods (see section below), which are called with a known class name at compile-time ... this cannot be used in static methods ...
Famous quotes containing the words methods and/or class:
“The philosopher is in advance of his age even in the outward form of his life. He is not fed, sheltered, clothed, warmed, like his contemporaries. How can a man be a philosopher and not maintain his vital heat by better methods than other men?”
—Henry David Thoreau (18171862)
“Thats how the Germans are.... The aristocrats at the top hard as glass, cold as ice, servants of the King, the working masses willing, pliable, sentimental, susceptible to brutality, the middle class educated and cowardly to the point of servility.”
—Alfred Döblin (18781957)