Chapter 2: Object Oriented Programming Concepts: Concepts Associated With OOP
Chapter 2: Object Oriented Programming Concepts: Concepts Associated With OOP
PROGRAMMING CONCEPTS
Concepts associated with OOP
Concepts of OOP:
Objects Polymorphism
Classes Overloading
Data Abstraction and Encapsulation Reusability
Inheritance
Explanation
As mentioned, definition of class starts with keyword class followed by name of
class(temp) in this case. The body of that class is inside the curly brackets and
terminated by semicolon at the end. There are two keywords: private and public
mentioned inside the body of class.
Objects
When class is defined, only specification for the object is defined. Object has same
relationship to class as variable has with the data type. Objects can be defined in
similary way as structure is defined.
Explanation of Program
In this program, two data members data1 and data2 and two member function
int_data() and float_data() are defined under temp class. Two objects obj1 and obj2 of
that class are declared. Function int_data() for the obj1 is executed using code
obj1.int_data(12);, which sets 12 to the data1 of object obj1. Then, function
float_data() for the object obj2 is executed which takes data from user; stores it in data2
of obj2 and returns it to the calling function.
Note: In this program, data2 for object obj1 and data1 for object obj2 is not used and
contains garbage value.
do if static while
Identifiers
In C++ programming, identifiers are names given to C++ entities, such as variables,
functions, structures etc. Identifier are created to give unique name to C++ entities to
identify it during the execution of program. For example:
int money;
int mango_tree;
Here, money is a identifier which denotes a variable of type integer. Similarly,
mango_tree is another identifier, which denotes another variable of type integer.