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:
“God of justice, save the people
From the clash of race and creed,
From the strife of class and faction,
Make our nation free indeed;”
—William Pierson Merrill (18671954)
“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 (18441911)