0% found this document useful (0 votes)
23 views

Features of OOPs

Features of Object oriented Programming Language

Uploaded by

sukhdev0887
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Features of OOPs

Features of Object oriented Programming Language

Uploaded by

sukhdev0887
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING

(OOP)

Object-Oriented Programming (OOP) is a paradigm that organizes software design around


data, or objects, rather than functions and logic. It is designed to model real-world entities and
their interactions using objects and classes. The core aim of OOP is to combine data and
methods that operate on the data into a single unit known as an object, thus providing several
advantages, such as modularity, reusability, and ease of maintenance.

Basic concepts of oop

• Class
• Object
• Comparison of Objects and Classes in C++
• Encapsulation
• Polymorphism
• Abstraction
• Inheritance
• Dynamic Binding
• Message Passing

1. CLASS: A class is a blueprint for creating objects. It defines a type of object according to
the data it holds and the operations that can be performed on it. In C++, a class is defined
using the class keyword followed by the class name and its members.

class ClassName
{
private:
// Data members (attributes)
public:
// Member functions (methods)
};

2. OBJECT: An object is an instance of a class. When a class is instantiated, it creates an


object that can access the data members and member functions defined by the class.

1
Comparison of Objects and Classes in C++

In Object-Oriented Programming (OOP), the concepts of classes and objects are fundamental
and closely related. Understanding their distinctions and relationship is crucial for effective
programming. Here’s a detailed comparison between objects and classes.

Concept Class Object


Definition Definition: A class is a blueprint or Definition: An object is an instance of
template for creating objects. It defines a a class. It represents a specific
type by specifying the data it holds realization of the class, with actual
(attributes) and the operations that can be values assigned to its attributes and the
performed on the data (methods). ability to perform operations defined by
Example: Think of a class as a blueprint its class.
for a house. The blueprint defines the Example An object is like an actual
layout and features of the house but is not house built from the blueprint. Each
a house itself. house (object) is a tangible instance
with specific details.
Purpose Purpose: To define a new data type and Purpose: To represent individual entities
specify the structure and behaviour of its that follow the structure and behaviour
instances. Classes encapsulate data and defined by a class. Objects hold specific
methods into a single unit. data and provide functionalities.
Example: A Car class defines what Example: An object like myCar of type
attributes and methods a car object will Car represents a specific car with
have. particular color, speed, and
functionality.
Characteristics Defines the structure (attributes) and Contains actual data and can perform
behavior (methods) but does not contain the operations specified by its class. It is
actual data. It is a static concept. a dynamic instance that interacts with
Example: The Car class might specify other objects and methods.
attributes like color and speed, and Example: The object myCar will have
methods like drive(), but these do not have its specific color and speed values and
values until an object is created. can use the drive() method to perform
actions.
Relationship Acts as a template or prototype. Multiple Is an instance of a class and follows the
objects can be created from a single class. template defined by the class. Objects
A class can be inherited by other classes to interact with each other and use
extend functionality. methods defined in their classes.
Example: You can create many Car Example: myCar can interact with other
objects (e.g., myCar, yourCar, hisCar) objects like yourCar and use methods to
from the Car class. perform operations based on the Car
class definition.
Memory No memory is allocated for a class itself. Memory is allocated when an object is
Allocation Memory is allocated only when objects are created. The size of the object depends
instantiated from the class. on the data members defined in the
class.

3. ENCAPSULATION: Encapsulation refers to the bundling of data (attributes) and


methods (functions) that operate on the data into a single unit or class. It also involves
2
restricting direct access to some of an object's components, which is a means of
preventing unintended interference and misuse. Following are objects of encapsulation

• Data hiding: Protects the internal state of an object by using private or


protected access specifiers.
• Public methods: Provide controlled access to the private data through public
functions.

4. ABSTRACTION: Abstraction is the concept of hiding the complex implementation


details and showing only the essential features of an object. It simplifies interaction
with objects by focusing on their functionality rather than their implementation.

Example: In a car object, the method drive() abstracts the complex operations involved
in driving, presenting a simple interface to the user.

5. POLYMORPHISM: Polymorphism means "many shapes" and allows objects of


different classes to be treated as objects of a common superclass. The most common
types are:

• Compile-time Polymorphism (Method Overloading): Multiple functions with


the same name but different parameters.
• Run-time Polymorphism (Inheritance and Virtual Functions): Ability to call
derived class methods through base class pointers.

6. INHERITANCE: Inheritance is a mechanism where a new class derives properties and


behaviours from an existing class. The new class, called a derived class, inherits
attributes and methods from the base class. Following are the types of Inheritance:

• Single Inheritance: A class inherits from a single base class.

3
• Multiple Inheritance: A class inherits from more than one base class.
• Multilevel Inheritance: A class is derived from another derived class.
• Hierarchical Inheritance: Multiple classes are derived from a single base class.
• Hybrid Inheritance: A combination of two or more types of inheritance.

7. BINDING: It refers to the association between a function call and the function
definition that gets executed. Binding can be broadly categorized into two types: static
binding and dynamic binding.

STATIC BINDING (also known as early binding) refers to the process where the function
call is resolved at compile time. In static binding, the function to be called is determined
based on the type of the object as known during compilation.

Characteristics:

• Compile-Time Resolution: The function call is resolved when the code is


compiled.
• Performance: Generally faster because the function address is known at compile
time.

DYNAMIC BINDING, or late binding, refers to the process of linking a function call to
the function definition at runtime. This is commonly achieved using virtual functions.

4
Characteristics:

• Run-Time Resolution: The function call is resolved when the program is


running, not during compilation.
• Virtual Functions: To achieve dynamic binding, the function must be declared
as virtual in the base class.

8. MESSAGE PASSING: Message Passing is the process of sending and receiving


messages between objects. In C++, this is achieved through method calls. It enables
communication between objects and is a fundamental concept in OOP.

You might also like