INTRODUCTION TO CLASSES AND OBJECTS - C++ PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in this in the previous session we have seen the structures concept and now we go with the object-oriented concept so that is interaction two classes and objects so here the C++ is supports the object-oriented programming so object-oriented programming means we can write the classes and objects so everything can be implemented with the help of these objects right now we will see what is a class and objects so class is a physical entity object logical entity a class is a blueprint object is an instance of casts that follow debate right so price is a structure and object is an instance of the class which follows this structure so gas is a physical entity object is a logical entity see for example we might some human human or you can go with the teacher right teacher each other isn't Cass teacher is a class so teacher and how the properties different properties and different methods right and logical entity is something something is a teacher Sandeep is it or chilled so which follows the properties of teaching similarly see a class can have attributes and methods or functions methods or functions so detail is a class at reduce so pressurization come on experience so all these are the attributes of a teacher qualification and functions each really right explain so there are different functions can be applied for a teacher similarly this is an object subject is an object of fatigue class teacher so something is an object which is a logical entity which is having a specialization experience qualification exactly I said right and coming to this one so can read write explain write rewrite explain so something can really write explain so something is in object teacher is in class so signal to a Sundy there will be some other teacher called ABC so ABC it will be having some experience south specialization and some qualification ABC will be having really tried explain and so on alright so one class can have a multiple instances one class can have a multiple objects right see just similar to our structure class will be also having the attributes and methods so class name and abuse methods right so we can't access these articles and methods directly just like a structure so how the structure variables can be accessed through the structure I mean structure members can be accessed only through structure Williams similarly in order to access these variables and methods these attitudes and methods objects you should be creative objects should be created and through the object the attributes can be accessed through the object the methods can be accessed only through the object so if you are creating any class so we have to in order to access the attributes are the methods of the class an object should be created and through the object only we have to access the we had to do same methods so how we create an object just similar to our structures the class name for a big object me task name followed by object name object name is created through the object that you put some methods to can be accessed right so I will give you a small example and then we'll go with the institution part so I'm creating a class teacher so character name int experience wild display here we can write name is equal to some Santi experience is equal to some typing and close and cash will be closed with the semicolon just like a structure and after published on this we have to write the range function so wide may wide me so here we have to view the scope of these variables as a completely so in the next session I will give you the expression of this control space best public private and correctly right so we mainly just write out of public so that all the variables and functions will be public to all the classes inside the person outside the class so here we have to in order to access this name and experience and this display function we have to create an object for this teacher and through the object we can access this one so teacher T 1 so T 1 is an object for integer class so T 1 dot display automatically this display function will be exist so in the absence of this T 1 it will not work because display is a function inside the class so in if the function is inside the class that that function can be accessed only with the helper object name so these functions we qualities and member functions and these are the member variables okay class members and member functions right in order to access these variables or influencers we have to create an object and do the object only we have to access the variables right so hope you understood these are classes and objects how to create a class and how to create an object and what are the contents available in the class right now so variables and methods in order to access the we have to create an object right now we'll see the implementation part of this class and objects hello heads so just now we have seen the introduction to classes and objects so now we will see the implementation of these classes in the working of this class so this is C++ also supports this object-oriented programming so we can write the class so we have to give the class name so let it be the class name is demo and here you can pass the parameters simply we can write the class name as a student and here we can write the attributes or remember variables and also functions inside the class so here we can we have to use the access specifiers as I have said earlier there are three access specifiers supported in C++ there is public private and protected C if you are not mentioning this public these access pisar is public so all the variables will be in a private would so what's the difference between the public private and protected so what actually happens when the variables are in a public or declared in private mode or a declared in protection so the major difference is scope of your radiation so where we have to use the variables so if it is a public those variables or the functions so we can use the public and for both the variables and functions so if the variables and member functions are public then those variables and functions can be accessed inside the class as well as outside the class outside the class means mean inside the main function false and if if it is declared as a private then those member functions or those variables can be only used within the class itself so those variables or functions cannot be used outside the class coming to the protected here it is also to our private access perspire but this can be used in inheritance in Hendon that means in the inheritance concept the variables and functions can also be used in derived class in the base class and derived class right yes now let's write the public character me int r number right now I'll buy the main function also we can write the function here we'll write the function also wide display similar to the structure inside the class coming to the main function here so if you want to access the name roll number and the display we have to create an object for the student and through the object we have to access the name and roll number just what happened in this structures concept the structure structure also in order to access the members of a structure we have to create the variable structure variable and then through the structure variable only we have to access the methods are the main functions or the variables so here also same but here we are declaring it as a class so here we can use the control space where's so that data can be hired so here I am creating this object for the class with the help of this one to see out enter name seeing yes dot name see out he in turn are nimble seeing start hard number and then simply you can write yes dot display and see out name stored me odd number right now let us say this one class dot CPP so this having no header files we have not included any header pipe here so hash include I was stream dot H has include on you not H to more to many types declaration so here you have to keep the semicolon that ends the class so straight by missing the semicolon here once again where you set the saving power but now let us execute this one so enter me so again giving Sun deep into our number again I am giving by 23 now you can observe the result inside the class named Sandy part number 523 yes so similar to our structure a class can be implemented the difference is here we can use their access specifiers the control specifiers it's a public private or product if you are not giving anything here by default it will be as it private see as this is the public so these variables and the methods can be accessed outside the main outside the classrooms also so in outside the class that means inside the main function we are accessing the methods in the way this one see if you created here try wait we can't access sorry right so if you compile you will get an error of student name is not accessible our number is not accessible display is not accessible because these variables and functions are declared in a private scope that means data is hidden so these can be accessed only inside the class itself see here we can write here see out enter the name right right see now here completely removing all these things and just I'm calling this function and again here I'm removing all these things and see this name is private our number is private so these can be accessed only inside the class itself also this displays also inside the private so again we'll get the error because we are using this display inside the main function that means outside the class which is declared as a private so if you change the scope of this method as a public see private these two variables are in the private and public the method is in public now the display function will be worked see you can observe here enter the name Sandeep 523 and you can observe here the name is Sandeep our number faculty because these name and our numbers are a primate so are in the private scope that means these variables can be accessed only inside the class so they cannot be out used outside the class so in main function we can't access this name in our number even though we are creating the object for a class we can't access this name in our number because these of these variables will be impressed and coming to this display function where we have changed this scope as a public so display function is a public so this function can be used inside the class as well as outside the class so outside the catchments inside outside the class with the help of that object created for this particular class so he'll remain function he'll created an object for the class yes and I am calling this function with the help of object SQR display so obviously this function will be executed because the scope of this function is public right so similarly there is a another control session called Project so I will explain that protect after completion of the inheritance concepts because if any variable or a function is given as a protected then the variables and functions can be accessed only inside the class as well as in the derived class so inheritance concept moves there are with Russell based class in such such situation we can use the members and functions which are created in a scope protected in both the derived class and peace class but not in the outside of the class right so hope you understood this is simple class and object and these access specifiers so if you are having any doubts regarding this one feel free to post your doubts in the comment section so that definitely I will try to clarify all your doubts and if you are really understood my sessions like musicians share my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 55,149
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, java programming, java basics, java fundamentals, beginners, programming fundamentals, java faq, jdk, jre, jvm, java introduction, source code, object oriented, oops, oop concepts, set classpath, abstraction, inheritance, polymorphism, encapsulation, class, object, secure, virtual machine, java compiler, platform independent, portable, robust, multithreading, method overloading, method overriding, strong typed, javac, class file, os dependent, oops example
Id: wlXCFNuVjBY
Channel Id: undefined
Length: 21min 51sec (1311 seconds)
Published: Fri Jan 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.