Method (computer Programming) - Class Methods

Class Methods

Class methods are methods that are called on a class (compare this to class instance methods, or object methods). Its meaning may vary depending on the programming language:

  • 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. this cannot 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, this refers to the class object.
  • Some languages have both. For example, in Python, one can create class methods and static methods using the classmethod and staticmethod decorators, 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)

Famous quotes containing the words class and/or methods:

    A revolution is not a dinner party, or writing an essay, or painting a picture, or doing embroidery; it cannot be so refined, so leisurely and gentle, so temperate, kind, courteous, restrained and magnanimous. A revolution is an insurrection, an act of violence by which one class overthrows another.
    Mao Zedong (1893–1976)

    Commerce is unexpectedly confident and serene, alert, adventurous, and unwearied. It is very natural in its methods withal, far more so than many fantastic enterprises and sentimental experiments, and hence its singular success.
    Henry David Thoreau (1817–1862)