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

Class and Object

The document provides an introduction to classes and objects in C++, fundamental concepts in object-oriented programming. It explains the types of classes, including abstract, concrete, and template classes, and illustrates the creation and functionality of objects through examples. Additionally, it describes member functions and their role in accessing and modifying object data, emphasizing the interaction between objects and their methods.

Uploaded by

fruydragon
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Class and Object

The document provides an introduction to classes and objects in C++, fundamental concepts in object-oriented programming. It explains the types of classes, including abstract, concrete, and template classes, and illustrates the creation and functionality of objects through examples. Additionally, it describes member functions and their role in accessing and modifying object data, emphasizing the interaction between objects and their methods.

Uploaded by

fruydragon
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Introduction to

Class in C++
Classes are fundamental to object-oriented programming (OOP).
They serve as blueprints for creating objects. Classes define data
members (attributes) and member functions (methods) that
objects will inherit.
What is Class and its
Types
A class is a user-defined data type that acts as a template for creating
objects. Common class types include abstract classes, concrete classes,
and template classes, each serving a specific purpose in program design.

1 Abstract Class 2 Concrete Class


An abstract class serves as a A concrete class, unlike an
blueprint for other classes, abstract class, can be
defining common methods instantiated and used to
and properties that derived create objects directly.
classes must implement.

3
A template class allows you to define a generic class that can work
with different data types, promoting code reusability and flexibility.
Examples of
Class
Let's look at an example of a class representing a 'Person'. It defines attributes like name, age, and methods like
introducing oneself.

Code Snippet Explanation


This code defines a 'Person' class with private data
class Person {
members 'name' and 'age', and public methods to access
private:
and modify these members.
string name;
int age;
public:
void setName(string n);
string getName();
void setAge(int a);
int getAge();
};
Introduction to Object in
C++
Objects are instances of classes. They are created from a class blueprint and
have their own distinct values for the data members defined in the class.
Objects can be used to represent real-world entities or concepts within a
program.

Blueprint (Class)
The class 'Person' acts as the blueprint for creating objects.

Instance (Object)
Each person object (like 'John', 'Jane', etc.) is a specific instance
of the 'Person' class.

Functionality
Each object has access to the methods defined in the class,
allowing it to perform actions specific to its type.
What is Object
An object is a real-world entity that has a state and behavior. In C+
+, objects are created from classes, inheriting the data members
and member functions defined in the class blueprint. They are like
unique instances of the class, possessing specific values for the
data members.
State Represents the data
members (attributes) of the
object, holding information
about its current condition.

Behavior Describes the actions or


methods that the object can
perform, defined by the
member functions of the
class.
Examples of
Object
Let's create a few 'Person' objects. Each object is an instance of the 'Person'
class, but they have different values for their name and age.

John
The object 'John' has the name "John" and age 25.

Jane
The object 'Jane' has the name "Jane" and age 30.

Emily
The object 'Emily' has the name "Emily" and age 22.
Functions of
Class
Functions associated with a class are known as member functions. They
define the behavior and functionality of objects created from that class.
Member functions operate on the data members of the class and can be
accessed using the object's name.

Accessor Mutator Function


Function
Functions that provide access Functions that modify the data
to the data members of a class members of a class. These are
without altering them. These often called "setter" functions.
are often called "getter"
functions.

Other Member
Functions
Functions that perform operations or tasks specific to the class, not
just accessing or modifying data members.
Functions of
Object
Objects interact with their member functions. When a member function is
called on an object, it operates on that specific object's data members. The
object's state is affected by the function's actions.

Function Call
1
A member function is called using the object name followed by
the function name, e.g. 'personObject.setName("Alice");'

Data Access
2
The function accesses and potentially modifies the data
members associated with the specific object it was called on.

State Change
3
The function's actions may change the object's internal data,
updating its state.

You might also like