Object Oriented Programming Features Part 4 | C ++ Tutorial | Mr. Kishore
Summary
TLDRIn this Nourish 80 video, Kishore explores the concept of objects in C++, explaining how they are created and how memory allocation occurs. He clarifies that classes are logical representations, while objects are their physical counterparts, requiring memory. Kishore also discusses the two ways to define member functions: inside or outside the class, emphasizing the importance of not including complex expressions within inline functions. The video serves as an educational guide on object-oriented programming, highlighting encapsulation as a key feature that binds data members and functions into a cohesive unit.
Takeaways
- 📘 The concept of a class in C++ is an extension of the C structure, allowing for the storage of various types of variables and member functions.
- 🔑 To access class members, an object of the class must be declared because the class itself is a logical representation and does not allocate memory until objects are defined.
- 🏷️ By default, all class members are private if no access specifier is mentioned, adhering to the principle of encapsulation.
- 🔄 Member functions can be defined inside or outside the class, with definitions inside the class being inline functions and not suitable for complex expressions or loops.
- 📝 When defining member functions outside the class, the scope operator (::) is used to indicate that the function belongs to the class.
- 🔑 To call member functions or access class members, at least one object of the class must be declared, as objects are the physical representation of the class.
- 📚 An object is defined as a class variable, an instance of a class, and the physical representation of a class, requiring memory allocation.
- 🔍 Each object created from a class can store data separately, allowing for the management of distinct data instances.
- 🔑 Encapsulation is a key feature of OOP, binding data members and member functions into a single unit called a class, promoting data integrity and abstraction.
- 📈 The script provides a foundational understanding of classes and objects in C++, emphasizing the importance of memory allocation and access methods for class members.
- 🎓 The explanation of class and object definitions, along with the concept of encapsulation, sets the stage for further exploration of OOP features in subsequent sessions.
Q & A
What is the primary function of a class in C++?
-A class in C++ serves as an extension of the C structure, allowing for the storage of different types of variables and member functions within it.
Why is it necessary to declare an object from a class?
-Declaring an object from a class is necessary to access the class members because memory is not allocated when the class is declared; it is only allocated when objects are defined.
What is the default access specifier for class members if none is specified?
-If no access specifier is mentioned, by default, all class members become private.
What are the two ways to define member functions in a class?
-Member functions can be defined either inside the class, which makes them inline functions, or outside the class, which does not make them inline.
Why should looping statements or complex expressions be avoided when defining member functions inside the class?
-Looping statements or complex expressions should be avoided in inline member functions because they can lead to code bloat and are not suitable for inlining.
What is the purpose of the scope operator (::) when defining a member function outside the class?
-The scope operator (::) is used to indicate that the function defined outside the class belongs to the class, clarifying the association between the function and the class.
How does the creation of an object relate to memory allocation in C++?
-When an object is created from a class, memory is allocated for that object, making it the physical representation of the class, whereas the class itself is a logical representation.
What is the difference between a class and an object in terms of memory allocation?
-A class, when declared, does not allocate memory. Memory is allocated only when objects (instances of the class) are created.
How many objects can be declared from a single class?
-You can declare any number of objects from a single class, each object having its own separate memory allocation for the class members.
What is encapsulation in the context of object-oriented programming?
-Encapsulation is the process of binding data members and member functions into a single unit called a class, thus encapsulating the data and the methods that operate on the data within the class.
Why is encapsulation an important feature in object-oriented programming?
-Encapsulation is important because it promotes the bundling of data and methods that operate on the data, providing data hiding and abstraction, which simplifies the management and maintenance of code.
Outlines
📘 Introduction to C++ Classes and Objects
This paragraph introduces the concept of classes and objects in C++. It explains that a class is an extension of a C structure, allowing the storage of different types of variables and member functions. The speaker clarifies the difference between declaring a class and defining an object, emphasizing that memory allocation occurs only when objects are defined. The explanation includes the default privacy of class members and the two methods of defining member functions: inline within the class and outside the class. The paragraph also touches on the importance of not including complex expressions or loops within inline functions.
🔍 Accessing Class Members and Member Functions
This section delves into how to access class members and member functions. It details the syntax for defining member functions both inside and outside the class, using the scope operator (::) to associate member functions with the class. The explanation includes how to declare objects to access class members and the distinction between logical and physical representations of data. The paragraph illustrates the process with an example of a 'student' class, showing how memory is allocated for objects and how to call member functions using the dot notation.
🏭 Understanding Objects and Encapsulation in OOP
The final paragraph provides a comprehensive understanding of what an object is in the context of object-oriented programming (OOP). It defines an object as a class variable, an instance of a class, and the physical representation of a class. The explanation covers the creation of multiple objects from a single class, each with its own memory allocation and data storage. The paragraph also introduces the concept of encapsulation, which is the bundling of data members and member functions into a single unit, and highlights its importance in OOP for managing data efficiently.
Mindmap
Keywords
💡Object
💡Class
💡Member Functions
💡Data Members
💡Encapsulation
💡Scope Operator
💡Inline Function
💡Memory Allocation
💡Access Specifiers
💡Constructor
Highlights
Introduction to the concept of class in C++ and its extension from C structure.
Explanation of how to declare an object to access class members.
Clarification that memory is not allocated upon class declaration but when objects are defined.
Definition of class members and how to access them through member functions.
The default privacy level of class members is private if not specified.
Two methods of defining member functions: inside or outside the class.
Inline member functions should not contain complex expressions or loops.
Syntax and process for defining member functions outside the class.
Class objects require memory allocation, unlike class declaration which is a logical representation.
The difference between logical and physical copies in the context of class variables and objects.
Process of creating class objects and allocating memory for them.
Accessing class members through object references using the dot notation.
Objects as instances of a class, allowing separate data storage for each instance.
The concept of encapsulation in object-oriented programming.
Encapsulation as the binding of data members and member functions into a single unit.
The practical application of encapsulation in managing data within objects.
The importance of objects in object-oriented programming for data management and maintenance.
Transcripts
[Music]
welcome to nourish 80 this is Kishore
and today we are going to continue the
oops features in last session we have
discussed the feature such as class okay
we have discussed the concept of class
and how to declare the object today I am
going to start what is an object okay
when object is created what happens
everything okay first of all what is an
object okay in C++
the new concept is nothing but class
actually we have discussed that class is
the extension of C structure and here
whenever the class is created we are
able to store different types of
variables and member functions inside of
the class now how to define the class
members means how to access the class
members to access the class members
first of all we should have to declare
an object from that class okay
now what is called an object and why we
need the object means to access the
class members we should have to define
the object why because when class is
declared the memory is not allocated
okay here the main point is when the
class is declared memory is not
allocated when objects are defined then
only memory is allocated because of
classes are the logical representation
of okay data that means logical logical
means what they are not existed they are
not physical okay for example I am going
to declare a class like this now class
student it is a student is the class
name next int ID and character name now
these are the data members now here I
have not used any access specific that
is why by default all the members will
become private members okay because of
by default the class visibility level or
X special
is private that is why here whenever the
axis specifier is not mentioned
automatically your compiler understands
their private member's next now to
access these members we have to go for
member function now public in public
area I am going to write like this while
you get next why to put now the class is
closed and already you have discussed
for that we can define the member
functions in two ways one is inside the
class another one is outside of the
class when inside the class it is
defined it will become in line member
function and here you have to take care
what is the clear means in C++ we can
define the member functions in two ways
one is inside the class another one is
outside of the class when the member
function is defined inside of the class
what happens now it will expand it
within in line okay it is expanded as an
inline function here we have to take
care about we do not have to write a
looping statements or complex
expressions inside the class that is why
here the important point is do not write
the looping statements or complex
expressions when the definition is
conducted inside the class okay next
second method is what writing outside
means defining the member function
outside a class when it is defined
outside it does not belongs to our does
not becomes to inline member function
that is why here we can define the
member function in two ways one is
inside the class another one is outside
the class for example when it is inside
the class how it is going to be okay now
I am going to give you when the
definition is inside what happens
suppose it is the get member function I
am going to take only one member
function that is get here I am going to
start like this
lawsy out see out enter student ID comma
name
x-c in ID name now function closed now
it is called number function definition
inside the class suppose when it is
outside how it is going to be now see
this I am going to define one more
function here brackets closed semicolon
and class also closed here watch it it
is a member function definition which is
conducted inside the class but here put
is a another member function which is
which is not defined inside the class
that means I am going to define this
function outside of the class when the
member function is defined outside of
the class the syntax is like this first
return type wide class name class name
is what student colon colon next one
member function put so here student is
the class name and the colon colon is
called
scope operator and it tells the put
belongs to s tu class ok here colon
colon is called scope operator and the
scope operator represents what the
function on it's right side belongs to
the class on its left side allow body C
out ID equal to ID okay suppose here I
am going to close like this next and L
later
C out name equal to name
now first of all ID is going to print
here later name is going to print here
it is how to define a member function
outside of the class and inside the
class next now the class is created data
members are ready and member functions
also ready now the remaining topic is
what how to call the member functions or
how to access the class members here it
is called class declaration and
definition now the point is how to
access the class members
whenever you are going to access the
class members first of all we should
have to declare the objects okay because
of object is the class variable under
when the object is declared when the
objects are defined then only memory is
allocated for example irregularly we are
using I and D a comma B comma C
generally ABC are called variables which
kind of variables means they're integer
kind variables are integer type
variables now what happens when these
variables are created okay how much
memory is allocated now six bytes memory
allocated and here one point is ABC are
integers and here one more integer is
there but actually it does not occupy
any memory because of it is the logical
copy and these are the physical copies
that is why here total it needs eight
bytes but here what happened only six
words memory is allocated because of
integer is easier to create the physical
copies that is why integer is the
logical copy ABC are the physical copy
now in our example int is the class and
a VCR the objects okay here in our
example int is nothing but a class and
ABC are the objects according to this
explanation objects needs the memory not
the class cursor class is a logical
representation objects are the physical
representation okay now what happens and
how to define the object okay now
according to this I am going to give the
class objects creation say this suppose
it is the main function and class name
is what s T you now yes here s tu is the
class name and s is the object now what
happens in stack
it is a just a zoom stack here it is the
s object now 2 bytes memory allocated
for ID and 20 bytes memory allocated for
name that is why this class object size
is 22 bytes next here another two
functions get suppose put now these are
the numbers of s object that is why to
call the gate input we have to write s
dot to get and s dot put it is how to
access the numbers thus why discover
nothing but calling okay now what
happens this gate and put members are
going to call okay now when s dot gate
is called program automatically goes to
get gate is nothing but this function it
is going to read the values for ID and
name when put is called program goes to
put function it is going to put into the
ident name that is why here the
important point is to access the class
members you should have to declare one
object at least one object through that
object we are able to access the class
members it is how to define a class and
object according to this okay according
to this object means now I am going to
explain what is an object according to
all these examples first definition of
object is it is a class variable R it is
a variable of type class it is one of
the definition for object it is a
variable of type class second one it is
a an instance of a class object is also
called it is an instance instance means
what here copy instance means copy that
is why object is also called it is a
copy of a class next third one it is
the physical representation of a class
okay here object is also called what it
is the physical representation of a
class just before we have discussed when
class is declared memory not allocated
when the objects are created then only
memory that is why objects require the
memory that is why it is the physical
representation of a class once a class
is declared we are able to declare any
number of objects from that class for
example in previous example I have given
student class student class contains
what ID name now from the student class
I want to declare the object s1 s2 s3
now these three are the objects now what
happened three memory locations are
created one is for s1 another one for s2
and another one for s3 and all are
having same data members ID ID ID on
here name name name here we can store
the first student data here second
student data here cloud select now
it is nothing but object over I entered
this one is called object that means
each object allows to store the data
separately that means each object
contains one student data now this data
is different from this data this data is
different from this data nowadays
everything is going on object oriented
because of this that is why object
oriented programming LoZ to manage the
data in the form of objects which is
easy to understand okay to maintain the
data that is nothing but object oriented
that is why object is defined in
different ways it is how to define the
object next another oops feature is
encapsulation now another important
feature of oopsies
encapsulation now encapsulation is
nothing but the process of binding the
data members and member functions into a
single unit called say this for example
here we have declared a class class
contains what int ID okay next name now
to access this we are going to use wide
gate and wide put functions now Watchi
here
ID and name are the what data members
and member functions now what happened
class allows the concept of a binding
the data members and member functions
together into a single unit called class
and this feature is called encapsulation
okay this which is called encapsulation
that is why encapsulation is a process
of defining different types of variables
and functions into a single unit called
class that is nothing but encapsulation
okay it is nothing but encapsulation
feature in this session we are going to
continue the remaining widgets thank you
for watching
[Music]
Просмотреть больше связанных видео
Object Oriented Programming Features Part 3 | C ++ Tutorial | Mr. Kishore
Features of Object Oriented Programming Part 2 | C ++ Tutorial | Mr. Kishore
Java Basic OOP Concepts | Features of OOPs in Java | Learn Coding
PHP Variable Storage & Object Comparison - Zend Value (zval) - Full PHP 8 Tutorial
Class Objects & Constructors | Godot GDScript Tutorial | Ep 16
Destructors in a Class | C++ Object Oriented Tutorial
5.0 / 5 (0 votes)