Introduction to OOP


C++, as we all know is an extension to C language and was developed by Bjarne stroustrup at bell labs. C++ is an intermediate level language, as it comprises a confirmation of both high level and low level language features. C++ is a statically typed, free form, multiparadigm, compiled general-purpose language. C++ is an Object Oriented Programming language but is not purely Object Oriented. Its features like Friend and Virtual, violate some of the very important OOPS features, rendering this language unworthy of being called completely Object Oriented. Its a middle level language.

C vs C++


The major difference being OOPS concept, C++ is an object oriented language whereas C language is a procedural language. Apart form this there are many other features of C++ which gives this language an upper hand on C laguage. Following features of C++ makes it a stronger language than C,
  • There is Stronger Type Checking in C++.
  • All the OOPS features in C++ like Abstraction, Encapsulation, Inheritance etc makes it more worthy and useful for programmers.
  • C++ supports and allows user defined operators (i.e Operator Overloading) and function overloading is also supported in it.
  • Exception Handling is there in C++.
  • The Concept of Virtual functions and also Constructors and Destructors for Objects.
  • Inline Functions in C++ instead of Macros in C language. Inline functions make complete function body act like Macro, safely.
  • Variables can be declared anywhere in the program in C++, but must be declared before they are used.

Importance of C++


  • C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features.
  • As one of the most popular programming languages ever created, C++ is widely used in the software industry. Some of its application domains include systems software, application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games. Several groups provide both free and proprietary C++ compiler software, including the GNU Project, Microsoft, Intel and Borland. C++ has greatly influenced many other popular programming languages, most notably Java.

More about class


  • 1. Class name must start with an uppercase letter(Although this is not mandatory). If class name is made of more than one word, then first letter of each word must be in uppercase. Example,
  • 2. Classes contain, data members and member functions, and the access of these data members and variable depends on the access specifiers (discussed in next section).
  • 3. Class's member functions can be defined inside the class definition or outside the class definition.
  • 4. Class in C++ are similar to structures in C, the only difference being, class defaults to private access control, where as structure defaults to public.
  • 5. All the features of OOPS, revolve around classes in C++. Inheritance, Encapsulation, Abstraction etc.
  • 6. Objects of class holds separate copies of data members. We can create as many objects of a class as we need.
  • 7. Classes do posses more characteristics, like we can create abstract classes, immutable classes, all this we will study later.

Data Abstraction and Encapsulation


Data Encapsulation combines data and functions into a single unit called Class When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible. Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details. Eg:calling sort() ,user don’t know the actual working behind it.

Polymorphism


Term means the ability to take more then one form. Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways.