Features of Object Oriented Programming Part 2 | C ++ Tutorial | Mr. Kishore
Summary
TLDRThis video script by Kishore from Nares introduces the fundamental concepts of Object-Oriented Programming (OOP). It explains the core features of OOP, such as classes, objects, data hiding, encapsulation, inheritance, and polymorphism. The script delves into the comparison between C structures and C++ classes, highlighting the extension of structures into classes with added benefits like data protection and the ability to design complex applications. It also clarifies the difference between structures and classes in C++, emphasizing the private access specifier in classes for secure data handling and the role of member functions in accessing private data, encapsulating the principles of data hiding and encapsulation.
Takeaways
- 😀 Object-Oriented Programming (OOP) is a programming paradigm that uses 'classes' and 'objects' to design applications.
- 🏫 The concept of 'class' in OOP is an extension of the C structure, allowing the bundling of data and functions together.
- 🔒 Data hiding in OOP is achieved by using private access specifiers, restricting access to class data members to only member functions within the same class.
- 📦 Encapsulation is the process of binding data and associated functions into a single unit, which is the class, providing a way to bundle data and methods that operate on the data.
- 🔑 Inheritance is a key feature of OOP that allows a new class to inherit properties and behaviors (methods) from an existing class.
- 📈 Polymorphism allows objects to be treated as instances of their parent class rather than their actual class, enabling a single interface to be used for a general class of actions.
- 🔄 Message communication is the mechanism by which objects interact with each other in OOP, typically through method calls.
- 📌 The 'structure' in C language is a collection of heterogeneous variables and is the foundation for OOP concepts, but lacks data protection and complex program design capabilities.
- 🔄 C++ extends the concept of structures by allowing the declaration of member functions and access specifiers, but still has the limitation of public data by default.
- 🛡️ The introduction of 'class' in C++ addresses the shortcomings of structures by providing private, protected, and public access levels, enhancing data security and supporting complex program design.
- 🔍 An object in OOP is an instance of a class, representing the physical manifestation of the class blueprint, with allocated memory for its data members when created.
Q & A
What does OOP stand for and what are its main features?
-OOP stands for Object-Oriented Programming. Its main features include class, object, data hiding, encapsulation, inheritance, polymorphism, and message communication.
What is a class in the context of OOP?
-A class in OOP is an extension of a C structure. It is a user-defined data type that allows the bundling of data and functions together into a single unit, which can then be used to create objects.
What is the difference between a C structure and a C++ structure?
-In C, structures can only contain variables, whereas in C++, structures can also contain member functions along with variables. However, by default, both C and C++ structures have public data members, which can be accessed from anywhere in the program.
Why were classes introduced in C++?
-Classes were introduced in C++ to address the issue of data protection that is not available in structures. Classes allow for the encapsulation of data and functions, and they support access specifiers like private, which restrict access to class members from outside the class.
What is the concept of data hiding in OOP?
-Data hiding in OOP is the practice of making class data members private, so they can only be accessed and modified by the class's member functions. This prevents unauthorized access and modification of the data from outside the class.
What is encapsulation and how is it achieved in a class?
-Encapsulation is the process of binding data and the associated functions together into a single unit or class. It is achieved by declaring data members and member functions within a class and using access specifiers to control access to these members.
What is an object in OOP?
-An object in OOP is an instance of a class. It is a variable of the class type and represents the physical manifestation of the class blueprint, holding actual data and being able to perform actions defined by its member functions.
How does a class act as a blueprint for creating objects?
-A class acts as a blueprint by defining the structure and behavior of the objects that can be created from it. When an object is instantiated from a class, memory is allocated for the object's data members, and the object can access the class's member functions.
What is the default access level for members in C++ classes and structures?
-In C++, the default access level for members in a class is private, whereas in C++ structures, the default access level is public.
Why are structures not suitable for designing large applications?
-Structures are not suitable for designing large applications because they do not support the concept of inheritance, which is crucial for creating extensible and maintainable code in large projects. Classes, on the other hand, support inheritance along with encapsulation and data hiding.
Can you access private data members of a class from outside the class?
-No, private data members of a class cannot be accessed from outside the class. They can only be accessed and modified through the class's member functions, ensuring data hiding and encapsulation.
Outlines
📘 Introduction to Object-Oriented Programming Concepts
This paragraph introduces the concept of Object-Oriented Programming (OOP), explaining its fundamental features such as class, object, data hiding, encapsulation, inheritance, polymorphism, and message communication. It emphasizes the importance of the 'class' concept, which extends the C structure, allowing for the grouping of heterogeneous variables under one name. The paragraph sets the stage for a deeper dive into the specifics of OOP, starting with the class concept and its relation to C structures.
🏭 Understanding C Structures as the Foundation of OOP
The speaker elaborates on C structures, which serve as the basis for OOP. A structure is a user-defined data type that can hold a collection of heterogeneous variables, making it an essential component for constructing objects in OOP. The paragraph provides an example of a 'student' structure, illustrating how it can store a student's ID, name, and subject-wise marks. It also discusses the memory allocation for structure variables and the process of accessing structure members. However, it points out the limitation of C structures, which is the lack of data protection due to public accessibility by default.
🔒 Transitioning from C Structures to C++ Classes for Enhanced Data Security
This paragraph discusses the transition from C structures to C++ classes, highlighting the introduction of data encapsulation and access specifiers like private, public, and protected in C++. It explains that while C++ structures can include member functions and have access specifiers, they lack the capability for complex program design and do not support inheritance, unlike classes. The paragraph emphasizes the importance of classes in C++ for creating secure and scalable applications due to their ability to restrict data access and support object-oriented features like inheritance.
🔑 The Role of Classes in Data Hiding and Encapsulation
The speaker explains the concept of data hiding and encapsulation in the context of C++ classes. Data hiding is achieved by declaring class members as private, restricting access to them by outside entities and allowing access only through member functions of the same class. Encapsulation is described as the bundling of data members and member functions into a single unit, which is the class. The paragraph provides an example of a 'student' class with private data members and a public member function to access them, illustrating how classes facilitate secure and organized code design.
🏗️ Class as a Blueprint and Object as an Instance in OOP
This paragraph delves into the distinction between classes and objects in OOP. It describes a class as a blueprint or an original copy from which multiple instances, or objects, are created. The class defines the structure and behavior of the objects, while objects are the actual instances that carry out the class's defined actions and store its data. The speaker uses the analogy of a blueprint for a building to explain the relationship between classes and objects, emphasizing that memory is allocated for objects only when they are created, not when the class is defined.
🎭 The Physical Representation of Objects in OOP
The final paragraph reinforces the concept of objects as the physical representation of a class. It reiterates that classes are logical constructs defining the properties and methods, while objects are the tangible entities that embody these definitions. The speaker likens the class to a blueprint and objects to the actual copies or instances made from that blueprint. This paragraph wraps up the session by summarizing the key points discussed about OOP features and their significance in software development.
Mindmap
Keywords
💡Object-Oriented Programming (OOP)
💡Class
💡Object
💡Data Hiding
💡Encapsulation
💡Inheritance
💡Polymorphism
💡Message Communication
💡Structure
💡User-Defined Data Type
💡Member Function
Highlights
Introduction to Object-Oriented Programming (OOP) and its features such as class, object, data hiding, encapsulation, inheritance, polymorphism, and message communication.
Explanation of 'class' as an extension of C structures, emphasizing the role of structures as the foundation for OOP.
Description of a structure as a collection of heterogeneous variables, allowing for the storage of different types of variables under one name.
Differentiation between primitive and derived data types in C language, with structures allowing the declaration of both types.
The concept of user-defined data types, with structures being an example due to their customizable nature based on requirements.
Illustration of how to use structures to store related data, such as student data including ID, name, and subject-wise marks.
The problem with C structures being that their data is public by default, leading to a lack of data protection.
Introduction of the class concept in C++ to address the issue of public structure data and to enable secure data handling.
Difference between C and C++ structures, with C++ allowing the declaration of member functions and access specifiers within structures.
The inherent issue with C++ structures being unable to design complex programs due to their public data by default.
The class in C++ as a blueprint for creating objects, with private data members being accessible only through member functions.
Concept of data hiding in classes, achieved by making data members private and accessible only via member functions.
Encapsulation defined as the binding of data members and member functions into a single unit, which is the class.
The role of objects as instances of a class, representing the physical realization of the logical class blueprint.
Explanation of how objects are created from classes and how memory is allocated for them, distinguishing between class and object.
The remaining OOP features to be covered in the subsequent session, indicating a continuation of the topic.
Transcripts
[Music]
welcome to Nares this is Kishore and
today we are going to start object
oriented Futures yesterday we have
discussed one concept that is what
objectoriented programming okay now we
are going to start object oriented
features what are the features available
in oops concept means oop oop stands for
objectoriented programming now in oop
concept the first main thing is class
later second one is nothing but object
next data hiding next encapsulation next
inheritance polymorphism message
Communications like this the whoops
features are we're having several okay
we are having several oops features what
they are one is nothing but class now
I'm going to start what is a class and
later we are going to discuss about
object later what is called Data hiding
what is called encapsulation everything
now we are going to start first uh the
whoops future that is nothing but
class now what is a class simply class
is is the extension of C structure okay
then that means we have to discuss about
C structure little bit generally in C
language generally in C language
structure means collection of
heterogeneous variables that means a
structure allows to store different
types of variables at one place under
one name okay okay that's why it is very
easy to construct object oriented
programming okay that's why generally
structures are the foundations for okay
structures are the foundations for
object oriented Concepts that means here
in object oriented programming we are
going to use the class but that class is
derived from means class is the
extension of C structure that's why
first time I'm going to discuss about
the C structure later we are going to
start the class concept now structure
means what it is collection of
heterogeneous variables okay otherwise
in other terms a structure is a user
defined data type and why it is called
user defined data types because of there
is a cause generally in C language we
are going to use some primitive data
types as well as we are going to use use
some derived data types for example
primitive data types means integers
float character now derived data type
means AR pointers and functions now we
are able to declare both
the Primitive and derived data type at
one place using the structure concept
for example I want to store some student
data means I want want to store one
particular student data now generally
every student contains what id number
name subject wise marks generally I have
to declare like this
suppose in ID just assume it is nothing
but the main
function now it is a main function and
the main function contains student ID
next student name
next every student is having subject
wise marks okay for example one student
is having six subjects now I have to
declare what six subjects suppose S1
S2 and
S6 here I have to declare six variables
for six subjects okay instead of this
can I declare array yes it is hone now
now in place of normal variables I'm
going to use
AR okay now here I can declare employee
details everybody that means they're
nonrelated data that means this program
allows to store nonrelated data but I
want to make it related that means I
want to store only the student data at
one place okay then in place of main
function I'm going to start
structure suppose structure name is
student now see this it is the student
structure and the student structure
contains first thing is id id is of
integer type and
S6 actually we are calling array okay
here ID is a normal variable and S is a
array type variable now here the point
is ID is a primitive data type and AR is
a derived data type now we are able to
store both primitive and derived data
type under one name called structure
okay that means the total structure is
constructed by the user based on the
requirement that's why structure is
called it is a user defined data type
that's why structure is called it is a
user defined data type next a structure
is also called complex data type because
of different types of variables are
stored under one name at one place okay
and due to this Advantage is what we can
maintain object oriented data means what
for example here it is the struct
keyword that denotes what we are going
to start a structure structure name and
structure members they are called and
here to work with this structure I'm
going to declare some variables like
this suppose S10 now what happens here
S1 S2 S10 are called structure
variables generally variables are stored
in stack that's why here just assume it
is the stack now it is the stack and
first structure variable S1 now this S1
require how many byes okay here ID is
the integer that's why it takes two
bytes and here S6 is six integers that's
why it require 12 btes now I'm going to
reduce this now three s of 3 now what
happened ID requires 2 bytes s of Three
6 bytes and name 20 that's why memory is
allocated like
this now it is a s one first two bytes
are allocated for ID now two
byes and later s of three is there now
what happen watch it here structure name
is what structure variable name S1 and
array name is yes now yes and three
integers memory allocated that means
total 6 bytes memory allocated and Base
address passord to yes and now
later name also there now now it is the
name and it requires total 20 bytes
that's why total this structure size is
28 bytes now the compiler is indicating
28 bytes required for this
structure okay like this the memory is
allocated for structure variables now to
access these members we are using S1 do
ID S1 do name S1 do subjects okay it is
a common thing and now structure allows
to store the data like this suppose it
is S1 structure data means here we are
able to store one student data one
student Marks One student name that
means all they are related to one
student here that one student is called
one object next S2 also same that S2
allows to store
second student data S3 S4 like this now
it is called object oriented that's why
structures are the
foundation now what is the problem with
structure okay now we are going to
discuss what is the disadvantage in
structure now the problem is in C
language in C language the structure
data is by default
public it is the main problem
that means what okay now the structure
data is accessible from anywhere in our
program through the structure variables
that means outside members other members
or member functions or functions anybody
can access the structure data that's why
structure data is not protected because
of structure data is public by default
structure members are public
okay now to avoid this problem they have
introduced the concept of class and one
more thing is in C++ also we are having
structures okay here the point is
actually we have discussed about C
language structure and actually our
topic is what C++ now we are having
structures in C++ also now what is the
difference okay in C language inside the
structure we are able to declare only
the variables which are called structure
members in C language inside the
structure we are able to declare only
the structure members means only the
variables only but in
C++ in C++ structure we can
declare strcture members and member
function
also it is the major
difference okay now we are able to
declare data members generally called
Data members okay which are also called
structure members and now C++ structure
allows to declare both the variables and
function inside the structure but C
structure never allows this kind of
Declaration it is the only difference
between C structure and C ++ structure
but here one point we have to discuss
that is what in C++ also the structure
data is public that means anybody can
access from anywhere that's why
structure data is not secured that's why
to avoid this problem okay they have
introduced class Concept in
C++ now in C++ how how the data is
secured that's why they have designed
the class like this the class data is
divided into private protected public
members in see there is no private
public protected only public is there
and in C++ structure also we are having
private protected public but here one
important thing is there what is that
thing okay here in C++ structure okay we
are are not able to Define complex
programs with the C++ structures we are
not able to design complex programs
means big project works but it is
possible with the class concept because
of classes allows the concept of
inheritance okay first observe it
carefully here one point is there
structure is available in C language and
all the structure members are public by
default in C language and C structure
allows only the variables inside the
structure which are called structure
members okay and now it is not protected
structure data is not protected now in
C++ what happened in C++ also they're
using structures but the only one
difference is okay here they have
introduced member functions they have
introduced member functions with private
public protected
declarations but the problem with the
C++ structure is they're not able to use
for Designing the big applications here
big application means project works it
is the major problem and here also
problem is data is public everybody can
access that's why to avoid this problem
in C++ which concept is introduced
class now what is a class class also
extension of C structure now according
to this explanation class is the
extension of C structure now the
difference is what in C++ there is a
rule what it is means the private data
of a class should be accessed with
member functions of same class it is the
main thing in previous discussion what
happens structure data is structure data
is accessed by okay structure members
and outers also in C++ structure the
structure data is accessed by structure
members outers in C structure also the
data is accessed by outers that's why C
and C++ structure data is not secured
that's why they have introduced one
formula what it is okay in C++ the price
prate data should be accessed only with
the member functions of same class now
what is called member functions okay
here the functions that are declared
inside the class are called member
functions that means outers are not
allowed okay certain rules and the
regulations are there that means certain
limitations are also there what it is
friend function pointers by using friend
functions and pointers we can access the
class data also but actually the rule is
what means the private data should have
to access with member functions of same
class okay that's why they have designed
class now how the class is working see
this suppose it is the
class suppose student class it is now
inside the student class I'm going to
use either
private or public or
protected later I'm going to declare the
data
members and member
functions now class and
semicolon see this here it is looking to
be the C++ structure now both are having
same but the only difference is here
private public protected declared now
and data members member function
declared here also we can but the major
difference is they are used in
inheritance concept means class allows
the concept of inheritance but structure
never allows the concept of inheritance
and now what happens since based on this
I'm going to give one small example
Suppose there is a class called
St and here I'm not going to mention
private or public automatically all the
members will become private and here in
C++ structure by default all the members
are public it is another important
difference between structure and class
that's why by default structure data is
public by default class data is private
now when it is private what happens
suppose private I'm going to declare
like this
now it is called visibility label or
access specifier later in
ID next character name of 20 next in
this section I'm going to write one
function public or private what it may
be then suppose public wi get now inside
this function I can access the ID and
name using C out and CNR directory what
it may be here ID and name are declared
inside the class under private and get
is declared in public section and inside
the get we are asking ID and name okay
here I'm going to access the ID and name
that means here where we are accessing
the data members that is inside the
member function here get is called
member function why because it is right
now member of this class that's why the
functions that are
declared inside a class are called
member functions and with the help of
member functions only we can access the
private data of a class that means now
this data is not accessible from outside
the class which is called Data hiding
which is called Data hiding okay
next it is available to only the member
functions and this concept is called
Data hiding that's why the key factor of
data hiding is achieved with private
declarations when the members are
private they can be accessed with the
member functions okay I'm giving small
example generally we are using mobile
phones now suppose one mobile phone is
there right now it is placed in my
pocket and
who is going to use this one me and my
family members okay and here there is no
permission required because of they my
family members my members and when it is
placed on the road when it is placed
outside now it is able to access by any
person because of now it is called
public okay when it is inside the pocket
it is private member that's why private
means restrict
only authorized people can access when
it is on the road means public anybody
can access now the structure data is
public and class data is private that
means outers are not able to access
without permission that's why user is
able to design secured applications
using C++ class concept okay that's why
class allows to
declare okay class allows to declare
both of the variables and functions at
one place now the variables are called
Data members and functions are called
member function that's why here what is
happening the data and functions both
are
associated okay and now according to
this explanation class is the
combination of data members and member
functions that's why simply class is
collection of of members that's why here
the main point is main point is classes
collection of members what kind of
members data members and member
functions now both are associated
together okay into a single unit called
class which is called
encapsulation that's why encapsulation
is the process of binding the data and
Associated functions together
into a single unit called
class this one is possible with class
that's why class provides the major
concept of data bind hiding data hiding
means insulating the data from external
access means outers are not allowed only
members can access it is called Data
hiding second one encapsulation means
Binding off or Tiding the data members
and member functions into a single unit
called class it is nothing but
encapsulation future both are provided
with class concept that's why here class
is a user defined data type with a
complex data okay here class is a user
defined data type or it is the extension
of C structure next here from class we
have to declare the variables for
example here structure is there there
now to access the structure members we
should have to declare the structure
variables we should have to declare the
structure variables then only the memory
is allocated in stack similar to that in
class also in class also to access the
data Members First memory have to be
allocated and when it is allocated means
when the objects are created now what is
called object here we are calling there
are structure variables here they are
called class variables here called class
variables and the class variables are
called objects that's why object meaning
is what it is a variable of type class
for example I'm going to declare like
this void
main now St s here s is
called object now it is nothing but a
variable of type class that's why object
meaning is class variables now the
memory also allocated for s means now s
is having data members now for data
members the memory is allocated that's
why to access the class members we have
to declare the objects later to access
the object members see this I'm going to
access like this for example s do get
now it is called
calling it is called calling that's why
to call or to access the class data
members or functions we should have to
use the object name now here this object
is Created from this class that's why
class is a
blueprint class is a blueprint to
construct the objects okay that's Sol I
said class is a user defined data now
I'm saying class is a blueprint here
blueprint means what original copy
blueprint means original copy to
construct the gerox copies gerox means
what instances now instances mean what
copies now the copies are nothing but
objects that's why to create the objects
we need the class that's why class is a
blueprint and object is the instance of
a class that's why another definition
already we have discussed what object is
a class variable now I am saying object
is the instance of a class and another
definition okay class okay here one
small point is there already have given
two explanations about object and the
next explanation is object is the
physical representation of a class
object is the physical IAL
representation of a class that means
what okay here I said class is the
blueprint means original copy and
objects are the gerox okay here the
point is when the object is created then
only memory allocated that means
according to this example class never
takes the memory means when class is
created memory not allocated when
objects are created then only memory
allocated means which requires the
memory means object that's why object is
the physical and class is The
Logical okay it is a major point now it
is nothing but what is a class what is
an object okay in this session I'm going
to cover the remaining whoops features
thank you for
[Music]
watching
[Music]
Parcourir plus de vidéos associées
![](https://i.ytimg.com/vi/_cbfR690u74/hq720.jpg)
Object Oriented Programming Features Part 3 | C ++ Tutorial | Mr. Kishore
![](https://i.ytimg.com/vi/AEo4KgwKYoU/hq720.jpg)
Java Basic OOP Concepts | Features of OOPs in Java | Learn Coding
![](https://i.ytimg.com/vi/mgU_ZAX7Gbs/hq720.jpg)
Object Oriented Programming Features Part 4 | C ++ Tutorial | Mr. Kishore
![](https://i.ytimg.com/vi/u99wAoBjDvQ/hqdefault.jpg?sqp=-oaymwEXCJADEOABSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLBWxeLOUOHCnY8dcEgkvVrFQTJy9w)
OOPS Interview Questions and Answers | Object Oriented Programming Interview Questions C#
![](https://i.ytimg.com/vi/5VXqrjH7PbQ/hqdefault.jpg?sqp=-oaymwExCJADEOABSFryq4qpAyMIARUAAIhCGAHwAQH4Af4EgALgA4oCDAgAEAEYZSBJKEMwDw==&rs=AOn4CLAEds4PbOd_Oq33k3v9rd1xN1mv9Q)
COS 333: Chapter 12, Part 1
![](https://i.ytimg.com/vi/I848HdWjLMo/hq720.jpg)
La Lógica de la Programación Orientada a Objetos explicada con Minecraft
5.0 / 5 (0 votes)