Class Declaration in C++ | C ++ Tutorial | Mr. Kishore

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi this is Kishore and welcome to nourish 80 today we are going to discuss about class sequence means in last session we are discussing about class and structure differences okay in law sufficient I have given class under structure different today completely I am going to start class next here's one more important topic er we have to discuss in last session I said C++ is an object-oriented programming language okay on here one important point is C++ is not a pure object-oriented programming language why because okay here we know that C is a function oriented programming language and we're discussing we how disgusted that C++ is object-oriented programming language because of in C language program is collection of functions that's why C is a function oriented but here sleeplessness program each collection of objects we have discussed that's why sleeplessness is called object oriented but here the problem is C++ is the extension of three language okay here C++ is the extension of C language which is also called superset of C language okay our extended version of C language or increment of say language that's why sleeplessness supports all the features of C heedlessness supports all the features of C language that means sleeplessness a loose to execute AC program with or without any modifications in C++ environment that means in sleeplessness the class is not mandatory with the help of functions also we can conduct C++ program but here the point is along with to those functions we are adding the classes and objects concept to the programming that's why here point these C++ supports function oriental concept under object-oriented concepts that is why C++ is not a pure object-oriented programming language and what are the pure object-oriented languages okay we are having separate if you draw a small talk okay now they are called a pure object-oriented programming languages okay over here Java is next small talk a field they are called what they are pure object-oriented programming languages faithlessness is not a pure object-oriented programming language next now how to create a class and what are the components of a class and later how to create an object from a class now first of all I am going to give you how to create a class with the syntax now I am going to start what is the class index faster class every class should have to startle it every class should have to start with class keyword class is a keyword unlit it denotes we are going to start a class here next every class how to maintain a name but here the point is class name is not mandatory in C++ okay class name is nothing but the structure a tag name in C language when compared with or c programming in C language every structure is having a tag name structure tag name which is optional and here also in C++ the class name is optional okay may be or may not know class and the next face tag name next here visibility label our access specifier next one we have to start private our oblique are protected now here private public protect what they are called means which are called access specifiers class access specifiers which are also called visibility levels under indicating the scope of the variables or functions means generally data members and member functions now here the access specifier our visibility level should have the individual colon symbol okay next here data type next commonly we are calling variable and same data type variable in equal next here we can declare functions also that's why here the return type later function and argument next same concept now here brackets close semicolon here also C++ class C++ in sleeplessness crash should be end with the semicolon that's why every class should have to start with the class keyword and later we have to provide the beginning and later member actually here they are called member okay and especially here variables they are called data members and here functions are called member functions next here what is access specifier or visibility level okay actually in C++ the main concept is what data hiding actually the data hiding is achieved with this private to declare okay sleeplessness main concept is they are hiding project the major difference between C programming and sleeplessness is what C programming it is public that means we can declare the variables touch any place and we can access from anywhere that's why C data is not protected because of it is public data to avoid that problem cichlid species introduces with data hiding feature which is the concept of class and in pass the main advantage is private declaration when the data numbers are private they can be accessed only with the number functions of same class here watch it return type function actually we are calling function but in our sleeplessness inside the class we are called a number functions now the point is in a class we are going to declare both of the variables and functions together into a single unit called a class which is called the encapsulation which is called encapsulation mechanism that's why encapsulation is the process of defining different variables means data members and functions means member functions into a single unit called a class it is called okay encapsulation like another concept is what data hiding hiding refers to be what okay here watch it variable variable unfunctional now the point is this data is available or this data is piled up with only the member functions that are declared inside the class when they are declared as private therefore here the main point when the data is private they should be accessible with the number functions of same class that means they are not accessible from outside of the class which is called data hiding that's why only the class numbers means especially number functions can access the private data it is called data hiding on this concept is a g-rated and here one more important topic private is optional okay here when there is no access specifier are okay actions operator visibility level then the default visibility level is always private next another one public the numbers that are declared using public can be excessively with number functions and outer functions also okay here the public members are actually with number functions as well as outer numbers also means outer functions also okay okay when the data is protected what happens this class can be accessible on this derived class it's a immediately derived class can be accessible that's why the protector remember okay here protector members are accessed only with what but class members under immediately derive the class members that means they are available minimum to two classes but which is possible with only inheritance concept which is possible only with the inheritance concept that's why in inherence what happens we are creating one class from another class that's why they are called derived and it is called base class which are also called super under which derived classes now here also same concept okay here the protected members are accessed with the super classes means the declared classes and immediately derived classes and further availability is dependent on visibility means level all inheritance more next now I am going to give one small example on this class next one more thing here we have to remember the tag name is optional I said when it is optional means when the objects are defined here okay here in between the close to the bracket and semicolon means close curly brackets and semicolons when the object is defined for example here object is there now an object is already defined there is no need of a tag name or class name okay actually tag name is here nothing more the class name that's why when all the objects are declared immediately followed by the class then there is no need of a class name suppose these objects are not defined then how to declare the object then it is the syntax first class name space or gift one objected to and semicolon object 1 , objected to answer meaning another point is here all these other objects which are derived from same class know what is here in object creation what we are doing we are going to use the class name that's why your class name is compulsory that's why whenever you are going to define the class objects in other places of the program then you should have to go for class name otherwise class name is optional now I am going to demonstrate one example now I am going to start a class just watch it for example class student now generally student is having what kind of data ID number every student is having ID number and every student is having a particular name suppose here I am going to decrease my weight okay now I declare private letter int ID next care name of twenty next here in this area public void read student under wide show student next few brackets closed semicolon now in this example St you is the class name esteem is a class name next private and public which are called access specifier are which are also called visibility levels okay access specifiers or which are also familiar with visibility label because of they are indicating they are indicating the visibility of beta inside the class or outside of the class that's why they are called visibility level just before how disgusted on the point when data is private it is not visible outside of the class when data is public it is visible to the class that's why here they are indicating availability or visibility of data that's why their caller access specifiers our visibility label next int ID n name generally we are calling variables but when they are inside the class they are called data member now they are called data members like to access this data already we know that suppose nobody the private data migration data should be accessible to the number functions of same class only because of it is not visible outside that's why when it classes private when total data members are private ok that class is useless class ok the class is use this class you shouldn't have to access with laser pointers like that that's why it is mandatory declared at least one member function in public area why because only the public numbers are visible outside and here we are going to declare this class objects in main generally that's why main means it is out of the class when data is private what happens when all the members are private they are not visible in our main function of then we are not able to access this private data that is why one function should have to maintain public otherwise see how to declare friend function otherwise you have to declare the friend function besides to avoid this problem it is better to declare member function in public area now these functions are called number functions okay now it is the class construction after class class name and data members number functions and along with access specifiers our visibility level next here what they are called member functions and everybody knows and here everybody knows that general a function consists of three parts one is what function declaration one is function calling another one is function definition here function declaration which is also called function prototype now here it is the function declaration part and we need the function definition and function calling but how how to define a function in C + v we can define a function in two is one is inside the class another one is outside of the class okay one is inside the class another one is outside of the class when inside the class what happens and when it is outside class what happens means when it is defined inside it will become inline member function remember this here when a member function is defined inside the class now that number function will become inline number function okay next when it is outside it is not inline member function when it is inline function program performance is decrease it and when it is outside program performance not decreased and when it is inside we are not able to make sure it is a rule there is a rule what is the rule means we are not able to write complex statements because of warnings are raised that's why in sleeplessness it is better to write the function outside the class and what is this int to define a function outside the class in next session we are going to discuss how to define number functions okay actually in this class I have given out to create a class how to define a class next in next session I am going to cover how to define number functions on how to define a object okay thank you for watching [Music]
Info
Channel: Naresh i Technologies
Views: 90,223
Rating: undefined out of 5
Keywords: Class, Declaration, c++, Class Declaration in C++, C ++ Tutorial, Kishore
Id: QmZuerApkOk
Channel Id: undefined
Length: 18min 15sec (1095 seconds)
Published: Mon Mar 27 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.