Object Oriented Programming: Chapter 1: Principles of Object Oriented Programming

Characteristics of Object Oriented Languages

Various characteristics of object oriented programming language are 1. Data encapsulation 2. Inheritance 3. Polymorphism 4. Dynamic binding 5. Data abstraction 6. Message passing

Characteristics of Object‒Oriented Languages

• Various characteristics of object oriented programming language are

1. Data encapsulation

2. Inheritance

3. Polymorphism

4. Dynamic binding

5. Data abstraction

6. Message passing

• We will understand these characteristics by understanding the basic concepts of object oriented programming


1. Objects

• Object is an instance of a class.

Objects are basic run‒time entities in object oriented programming.

• In C++ the class variables are called objects. Using objects we can access the member variable and member function of a class.

•  Object represent a person, place or any item that a program handles.

• For example ‒ If the class is country then the objects can be India, China, Japan, U.S.A and so on.

• A single class can create any number of objects.

• Declaring objects ‒

The syntax for declaring object is

Class _Name   Object _Name;

• Example

Fruit fl;

For the class Fruit the object f1 can be created.

 

2. Classes

A class can be defined as an entity in which data and functions are put together.

• The concept of class is similar to the concept of structure in C.

• Syntax of class is as given below

class name_ of _class

{

 private :

variables declarations;

function declarations;

public:

variable declarations;

function declarations;

};← do not forget semicolon

Example

class rectangle

{

private :

int len, br;

public:

void get_data();

void area();

void print_data ();

};

• Explanation

* The class declared in above example is rectangle.

* The class name must be preceded by the keyword class.

* Inside the body of the class there are two keywords used private and public. These are called access specifiers.

* By default the data and function declaration is of type of private. When data and functions are declared as private then only members of same class can access them. This achieves the data hiding property.

* The public access specifier allows the function declared outside the class to access the data and functions declared under it.

* Hence the functions get_data(), print_data () and area() can be accessed by any other function (even though the outside functions). But the data members len and br cannot be accessible by the functions that are outside the class rectangle.


• Rules for declaring class name

1. The class name must begin with the letters, it may be followed by letters or digits or underscore.

2. The name of the class must not be same as the keyword or reserved word.

3. The class name must not contain any special character such as ~! @ # $ % ^ &* () { } []+ ‒

 

3. Encapsulation

• Encapsulation means the detailed implementation of a component which can be hidden from rest of the system.

• In C++ the data is encapsulated.

• Definition : Encapsulation means binding of data and method together in a single entity called class.

• The data inside that class is accessible by the function in the same class. It is normally not accessible from the outside of the component.


Concept of Encapsulation

 

4. Inheritance

Definition: Inheritance is a property by which the new classes are created using the old classes. In other words the new classes can be developed using some of the properties of old classes.

Example :


• Inheritance support hierarchical structure.

• The old classes are referred as base classes and the new classes are referred as derived classes. That means the derived classes inherit the properties (data and functions) of base class.

• Here the Shape is a base class from which the Circle, Line and Rectangle are the derived classes. These classes inherit the functionality draw() and resize(). Similarly the Rectangle is a base class for the derived class Square. Along with the derived properties the derived class can have its own properties. For example the class Circle may have the function like backgrcolor() for defining the background color.

 

5. Reusability

• Defintion : Reusability means making use of existing class by adding the additional features and capabilities within it.

• The existing class need not have to modify. This is possible by deriving a new  class from the existing class and adding the desired functionalities to this new class.

• Inheritance provides the facility of reusability.

 

6. Polymorphism

 • Polymorphism means many structures.

Definition: Polymorphism is the ability to take more than one form and refers to an operation exhibiting different behavior in different instances (situations).

• The behavior depends on the type of data used in the operation. It plays an important role in allowing objects with different internal structures to share the same external interface.

• Without polymorphism, one has to create separate module names for each method.

• For example the method clean is used to clean a Dish object, one that cleans a Car object, and one that cleans a vegetable object.

• With polymorphism, you create a single "clean" method and apply it for different objects.

 

7. Dynamic Binding

• Binding refers to the linking of a procedure call to the code to be executed in response to the call.

• In Static binding which function is to be called for a particular object is determined at the compile time. Selection of particular function for call is based on the type of formal parameters.

• Definition: Dynamic binding is the runtime determination of which function to call for a particular object of descendant class based on the type of argument.

• In dynamic binding the code associated with a given procedure call is not known until the time of the call at run‒time.

Example: Suppose you declared two classes: Rectangle and then Square. In both these classes there is a function draw(point1,point2). Then, each time a call is made to MyObject.draw(point1,point2), then version of draw that is called will depend on whether My Object is for a Rectangle class or for a Square class.

 

8. Data Abstraction

Definition: Data abstraction means representing only essential features by hiding all the implementation details. In C++, class is an entity used for data abstraction purpose.

Example

class Student

{

int roll;

char name [10];

public;

void input ( );

void display ( );

}

In main function we can access the functionalities using object. For instance

Student obj;

obj.input ( );

obj.display ( );

Thus only abstract representation can be presented, using class.

Difference between Encapsulation and Abstraction


Data encapsulation

1. It is a process of binding data members of a a class to to the member functions of that class.

2. Data encapsulation depends upon object data type.

3. It is used in software implementation phase.

4. Data encapsulation can be achieved by inheritance.

Data abstraction

1. It is the process of eliminating unimportant details of a class. In this process only important properties are highlighted.

2. Data abstraction is independent upon object data type.

3. It is used in software design phase.

4. Data abstraction is represented by using abstract classes.

 

Review Questions

1. Explain in detail about various object oriented concepts.

2. Explain the characteristics of OOPs in detail.

3. List out the features of object oriented programming.

4. Distinguish between abstraction and encapsulation.

5. Explain the following concepts of object oriented programming in detail with an example

 i) Data encapsulation ii) Inheritance

6. Explain briefly about various object oriented programming concepts and show how C++ supports them.

7. Explain the major principles of object oriented programming with illustrations and neat diagram.

8. Explain the characteristics of OOPs.

 

Object Oriented Programming: Chapter 1: Principles of Object Oriented Programming : Tag: Oops, Computer Programming : - Characteristics of Object Oriented Languages


Object Oriented Programming: Chapter 1: Principles of Object Oriented Programming



Under Subject


Object Oriented Programming (OOPs)

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Applied Physics (CSIE) II

PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Digital Principles and Computer Organization

CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electrical and Electronics Engineering

EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Object Oriented Programming (OOPs)

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Object Oriented Programming (OOPs) - Laboratory

CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation