Class and Object:
Defining the Class
Here’s the definition (sometimes called a specifier) for the class syllabusme,
examples:
class syllabusme //define a class
{
private:
int somedata; //class data
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “\nData is “ << somedata; } };
The definition starts with the keyword class, followed by the class name—smallobj in this example. Like a structure, the body of the class is delimited by braces and terminated by a semicolon. (Don’t forget the semicolon. Remember, data constructs such as structures and classes end with a semicolon, while control constructs such as functions and loops do not.)
private and public:
The body of the class contains two unfamiliar keywords: private and public. What is their
purpose?
A key feature of object-oriented programming is data hiding. This term does not refer to the activities of particularly paranoid programmers; rather it means that data is concealed within a class so that it cannot be accessed mistakenly by functions outside the class. The primary mechanism for hiding data is to put it in a class and make it private. Private data or functions can only be accessed from within the class. Public data or functions, on the other hand, are accessible from outside the class.
Defining the Class
examples:
class syllabusme //define a class
{
private:
int somedata; //class data
public:
void setdata(int d) //member function to set data
{ somedata = d; }
void showdata() //member function to display data
{ cout << “\nData is “ << somedata; } };
The definition starts with the keyword class, followed by the class name—smallobj in this example. Like a structure, the body of the class is delimited by braces and terminated by a semicolon. (Don’t forget the semicolon. Remember, data constructs such as structures and classes end with a semicolon, while control constructs such as functions and loops do not.)
private and public:
A key feature of object-oriented programming is data hiding. This term does not refer to the activities of particularly paranoid programmers; rather it means that data is concealed within a class so that it cannot be accessed mistakenly by functions outside the class. The primary mechanism for hiding data is to put it in a class and make it private. Private data or functions can only be accessed from within the class. Public data or functions, on the other hand, are accessible from outside the class.
This was a great blog. Really worth reading it. Thanks for spending time to share this content with us.
ReplyDeleteIELTS Coaching Centre in Tambaram
IELTS Coaching Centre in Velachery
IELTS Classes in T Nagar
Best Spoken English Classes in Chennai
Spoken English in Chennai
IELTS Chennai
English Speaking Course in Mumbai
Spoken English Classes in Mumbai
IELTS Center in Mumbai
IELTS Mumbai