In a hierarchy of classes a sub class inherits all of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: an object and a subprogram call. In the former case, the object executes the appropriate method with its own local data, whereas in the latter case the data to be processed is usually sent along with the subprogram call to the subprogram code unit. Class A class is a description of one or more similar objects. The class concept is similar to "type" in the conventional procedure-oriented languages. For example, if "integer" is a type (class), then "8" is an instance (object) of type (class) "integer". Similarly, "Person-1" and "Person-2" can be two instances (objects) of a class "Person". Multiple instances of a class can be created which are known as the objects of the class. Each object has its own local data and represents a different instance of its class. Since all the objects of a class share the same methods, the only difference between two objects of the same class is the state of their local variables. Also note that there can be two categories of object variables - class variables and instance variables. Class variables are variables stored in the class whose values are shared by all instances (objects) of the class. Instance variables are variables for which local storage is available in the instances (objects). Object-oriented programming languages also support class hierarchies. Subclasses of a given class are refinements of it, inheriting the functionality and local variables of the parent-class, or super-class. Sub-classes can add new local variables and methods and can modify or hide inherited methods. Inheritance In OOP, inheritance is a mechanism for sharing code and behavior. It allows a programmer to reuse the behavior of a class in the definition of new classes. We saw above that a program written in an object-oriented language may have a large hierarchy of classes. In fact, good programming in an object-oriented language depends, to a large extent, in creating sub-classes of existing classes because this leads to potential reuse...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online