Object-oriented programming: Difference between revisions

Content deleted Content added
WikiCleanerBot (talk | contribs)
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation)
Inheritance: Change 'attributes' to 'variables'. Attribute generally means 'value of variable' which is not what is intended here.
Line 108:
OOP languages are diverse, but typically OOP languages allow [[Inheritance (object-oriented programming)|inheritance]] for code reuse and extensibility in the form of either [[class (computer science)|classes]] or [[Prototype-based programming|prototypes]]. These forms of inheritance are significantly different, but analogous terminology is used to define the concepts of ''object'' and ''instance''.
 
In [[class-based programming]], the most popular style, each object is required to be an [[instance (computer science)|instance]] of a particular ''class''. The class defines the data format or [[data type|type]] (including member variables and their types) and available procedures (class methods or member functions) for a given type or class of object. Objects are created by calling a special type of method in the class known as a [[Constructor (object-oriented programming)|constructor]]. Classes may inherit from other classes, so they are arranged in a hierarchy that represents "is-a-type-of" relationships. For example, class Employee might inherit from class Person. All the data and methods available to the parent class also appear in the child class with the same names. For example, class Person might define variables "first_name" and "last_name" with method "make_full_name()". These will also be available in class Employee, which might add the variables "position" and "salary". It is guaranteed that all instances of class Employee will have the same attributes (variables, not their values), such as the name, position, and salary. Procedures and variables can be specific to either the class or the instance; this leads to the following terms:
 
* [[Class variable]]s – belong to the ''class as a whole''; there is only one copy of each variable, shared across all instances of the class