Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Data Abstraction and Encapsulation

 The wrapping up of data and functions into a single unit (called class) is known as
Encapsulation.
 The data is not accessible to the outside world and only those functions which are
wrapped in the class can access it. These functions provide the interface between
the object’s data and the program.
 The main idea of encapsulation is hiding of internal details of an object from an
unauthorized access or even alteration from other objects in the system.
 This insulation of the data from direct access by the program is called data hiding or
information hiding.
 The data and function may be private or public.
 Abstraction: refers to the act of representing essential features without including the
background details or explanation.
 Since the classes use the concept of data abstraction, they are known as Abstract
Data Types (ADT).
Inheritance
 Inheritance is the process by which objects of one class acquire the property of
objects of other class.
 It supports the concept of hierarchical classification.
 In OOP, the concept of inheritance provides the idea of reusability. This means
that we can add additional feature to existing class without modifying it.
 Each sub-class defines only those features that are unique to it.
Polymorphism:
 Polymorphism means the ability to take more than one form.
 An operation may exhibit different behavior in different instances. The behavior
depends upon the types of data used in the operation.
 Polymorphism can be of two types:
 Operator Overloading
 Function Overloading.
Dynamic Binding
 Binding refers to the linking of a procedure call to the code to be executed in a
response to the call.
 Dynamic Binding (Late Binding) means that the code associated with a given
procedure call is not known until the call at run-time.
 It is associated with polymorphism and inheritance.

Message Passing:
 An object-oriented program consists of a set of objects that communicate with
each other.
 A message for an object is a request for execution of a procedure and
therefore will invoke a function in the receiving object that generates the
desired results. Message passing involves specifying the name of the object, the
name of the function and the information to be sent.
Beginning with C++
 C++ is an Object oriented programming language.
 It was developed by Bjarne Stroustrup at AT&T Bell Laboratories in early 1980s.
 C++ is an extension of C with major addition of the class construct feature.
 The facilities that C++ adds on to C are classes, inheritance function overloading and
operator overloading.
 These features enable creation of Abstract Data Types, inherit properties from existing
data types and support polymorphism.
 Easy to expand and maintain.
 Follows Bottom-up Approach. Lower level tasks are first carried out and are then
integrated to provide the solution of a single problem.
Simple C++ Program
 Like C, C++ statements terminate
with semicolon.
 Comments start with a double slash
symbol and terminate at the end of
line.
 A double slash comment is basically
a single line comment.
 The comment symbols /*, */ are still
valid and more suitable for multiline
comments.
Output Operator
 The statement
cout<<“Welcome to C++ \n”;
Causes the string in quotation marks to be displayed on the screen.
 This statement introduces two new C++ features, cout and <<.
 The identifier cout is a predefined object that represent the standard
output stream in C++. Here the standard output stream represent the
screen.
 The operator << is called the insertion or put to operator. It inserts (or sends)
the contents of the variables on its right to the object on its left.
The iostream file
 #include<iostream> this directive causes the preprocessor to add the
content of the iostream file to the program.
 It contains the declaration of the identifier cout and the operator <<.
 The header files should be included at the beginning of all the programs.

Namespace:
 Namespace defines a scope for the identifiers that are used in a program.
 For using the identifiers defined in the namespace scope we must include the
using directive like
using namespace std;
 Here std is the namespace where ANSI C++ standard libraries are defined.
 All ANSI C++ programs must include this directive. This will bring the identifiers
defined in std to the current global scope.
 Using and namespace are the keywords in C++.

You might also like