Classes and Inheritance 1 Classes How are objects defined? An object is defined via its class,which determines everything about an object.Objects are individual instances of a class.A method is simply the action that a message carries out.It is the code,which gets executed when the message is sent to a particular object. Classes serve as templates from which objects can be created.C1asses have the same instance variables and operations as corresponding objects but their interpretation is different.Instance variables in an object represent actual variables while class instance variables are potential,being instantiated only when an object is created.We may think of a class as specifying a behavior common to all objects of the class.The instance variables specify a structure (data structure) for realizing the behavior.The public operations of a class determine its behavior while the private instance variables determine its structure.Private copies of a class can be created by a make-instance operation,which creates a copy of the class instance variables that may be acted on by the class operations.Syntactically,a class can be represented as: name:class instance variables ... class variables ... instance methods ... class methods ... Classes specify the behavior common to all elements of the class.The operations of a class determine the behavior while the instance variables determine the structure. 2 Inheritance In the world at large,it is often possible to arrange concepts into an inheritance hierarchy——a hierarchy in which each concept inherits the properties of the concept immediately above it in the hierarchy. For example, we might classify different kinds of vehicles according to the inheritance hierarchy in Figure 5-3. Moving down the hierarchy, each kind of vehicle is more specialized than its parent (and all of its ancestors) and is more general than its child (and all of descendants). A wheeled vehicle inherits properties common to all vehicles (it holds one or more people and carries them from place to place) but has an additional property that makes it more specialized (it has wheels). A car inherits properties common to all wheeled vehicles but also has additional, more specialized properties (four wheels, an engine, a body, and so forth). The inheritance relationship can be viewed as an is-a relationship.Every two-door car is a car,every car is a wheeled vehicle,and every wheeled vehicle is a vehicle. Inheritance allows us to reuse the behavior of a class in the definition of new classes.Subclasses of a class inherit the operations of their parent class and may add new operations and new instance variables. Inheritance captures a form of abstraction called super-abstraction, that complements data abstraction. Inheritance can express relations among behaviors such as classification, specialization, generalization, approximation, and evolution. The ability to classify classification of classes provides greater classification power and conceptual modeling power. Classification of classes may be referred to as second-order classification. Inheritance provides second-order sharing, management, and manipulation of behavior that complements first-order management of objects by classes. Syntactically, inheritance may be specified in a class as: name:class super class ... instance variables {as before}