Method (computer Science) - 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 Science)

Famous quotes containing the words class and/or methods:

    What exacerbates the strain in the working class is the absence of money to pay for services they need, economic insecurity, poor daycare, and lack of dignity and boredom in each partner’s job. What exacerbates it in upper-middle class is the instability of paid help and the enormous demands of the career system in which both partners become willing believers. But the tug between traditional and egalitarian models of marriage runs from top to bottom of the class ladder.
    Arlie Hochschild (20th century)

    I believe in women; and in their right to their own best possibilities in every department of life. I believe that the methods of dress practiced among women are a marked hindrance to the realization of these possibilities, and should be scorned or persuaded out of society.
    Elizabeth Stuart Phelps (1844–1911)