Вы находитесь на странице: 1из 2

1. Introduction to C++ C++ is an object-oriented programming language.

It was developed by Bjarne Strou strup at AT&T Bell Laboratories in Murray Hill, New Jersey, USA, in 1980's. He w anted to create a powerful language that could support object-oriented programmi ng features and still retain the power and style of C. The result was C++. The c lass was a major addition to the original C language, Stroustrup initially calle d the new language 'C with classes'. In 1983, the name was changed to C++. The i dea of C++ comes from the C increment operator ++, thereby suggesting that C++ i s an augmented or incremented version of C. C++ is a superset of C. Almost all C programs are also C++ programs. However, th ere are a few minor differences that will prevent a C program to run under C++ c ompiler. The most important facilities that C++ adds on to C are classes, inheritance, fu nction overloading, and operator overloading. These features enable creating of abstract data types, inherit properties from existing data types and support pol ymorphism, thereby making C++ a truly object-oriented language. The object-orien ted features in C++ allow programmers to build large programs with clarity, exte nsibility and ease of maintenance, incorporating the spirit and efficiency of C. Encapsulation The most important feature of a class is encapsulation. The wrapping up of data and functions into a single unit (called class) is known as encapsulation. The d ata is not available to the outside world, and only those functions which are wr apped in the class can access it. These functions provide the interface between the object's data and the program. This insulation of the data from direct acces s by the program is called data hiding or information hiding. Data Abstraction The act of representing essential features without including the background deta ils or explanations is known as abstraction. Classes use the concept of abstract ion and are defined as a list of abstract attributes such as size, weight and co st, and functions to operate on these attributes. They encapsulate all the essen tial properties of the objects that are to be created. The attributes are someti mes called data members because they hold information. The functions that operat e on these data are sometimes called methods or member functions. The classes us e the concept of data abstraction, they are known as Abstract Data Types (ADT). Inheritance The process by which one object acquires the properties of another object is kno wn as inheritance. OR Inheritance is a mechanism in object oriented programming to design two or more entities that are different but share many common features . Inheritance is the mechanism which allows a class A to inherit properties of a c lass B. We say A inherits from B . Objects of class A thus have access to attribute s and methods of class B without the need to redefine them. If class A inherits from class B, then B is called superclass of A. A is called subclass of B. Super classes are also called parent classes. Subclasses may also be called child clas ses or derived classes. For example, a Red Delicious apple is part of the classification apple, which in turn is part of the fruit class, which is under the larger class food. Without the use of classifications, each object would have to define explicitly all of i ts characteristics. However, through the use of classifications, an object need only define those qualities that make it unique within its class. It is the inhe ritance mechanism that makes it possible for one object to be a specific instanc e of a more general case. Inheritance is an important aspect of object-oriented programming. Inheritance is not limited to one level. A subclass can be a superclass of other classes, forming an inheritance hierarchy. Consider an example shown in the following figure. In the above example the Student is the base or super cla ss and the Graduate and Undergraduate are the derived class or subclass. The Gra

duate is the super class for the Masters, Doctoral and Law and this three are th e subclass. And the Undergraduate is the superclass for Commuting and Resident a nd this two are the subclass. Inheritance is very powerful and if it is properly used, complex programs can be developed very efficiently.

Вам также может понравиться