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:
“Take away from the courts, if it could be taken away, the power to issue injunctions in labor disputes, and it would create a privileged class among the laborers and save the lawless among their number from a most needful remedy available to all men for the protection of their business interests against unlawful invasion.... The secondary boycott is an instrument of tyranny, and ought not to be made legitimate.”
—William Howard Taft (18571930)
“It would be some advantage to live a primitive and frontier life, though in the midst of an outward civilization, if only to learn what are the gross necessaries of life and what methods have been taken to obtain them.”
—Henry David Thoreau (18171862)