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.
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
classmethodandstaticmethoddecorators, respectively. The former has access tothis(i.e. the instance object, conventionally known asself), while the latter does not.
Read more about this topic: Method (computer Programming)
Famous quotes containing the words class and/or methods:
“He could jazz up the map-reading class by having a full-size color photograph of Betty Grable in a bathing suit, with a co- ordinate grid system laid over it. The instructor could point to different parts of her and say, Give me the co-ordinates.... The Major could see every unit in the Army using his idea.... Hot dog!”
—Norman Mailer (b. 1923)
“With a generous endowment of motherhood provided by legislation, with all laws against voluntary motherhood and education in its methods repealed, with the feminist ideal of education accepted in home and school, and with all special barriers removed in every field of human activity, there is no reason why woman should not become almost a human thing. It will be time enough then to consider whether she has a soul.”
—Crystal Eastman (18811928)