Class And Encapsulation In C++

class and encapsulation
class and encapsulation

Class And Encapsulation In C++:-

In this article I have explained class and encapsulation in c++ in detail with effective way.

You will like it , I know about it. So enjoy it lovely friends. The concept of

class and encapsulation in c++ is most important to get c++ in detail.

Class:-

Class is an unit in which data and it’s associated function put together. It is a main feature of Object Oriented Programming language.

With the help of keyword class, we can define a class.

Syntax,

class       <classname>

{

public:

datamembers;

memberfunction;

};

In above syntax    class is a keyword. classname is an identifier where we can write any  name related to our working of that class. We must follow some important rules of declaring identifier. Here { is known as opening brace and } is known as closing brace. These both are used to contain the properties of class here and to create a block of statements.

In this syntax, we have used public that is  an access specifier. It is also known as Visibility Control or Access Modifier.

Datamembers are indicating all the variables that we have to declare.

Memberfunction are indicating all the functions that we have to declare.

Datamember and Member Function are combindly known as properties of a class.

Here we have used ‘;’ sign to tell or specify that class definition has completed.

In  C++ language default access specifier is private .   If we want to keep private  to our class properties then we don’t need to write it as we have written public specifier.

Like this we can hide and protect our data to create a class.

Example:-

class sum

{

int a,b;

public:

void putdata (int x, int y)

{

a=x;

b=y;

}

void add ()

{

int sum=a+b;

cout<<”/n sum is:=-“<<sum;

}

};

void main()

{

clrscr();

sum s1;

s1.putdata(5,10);

s1.add();

getch();

 

Output:-

sum is :- 15

Object:-

Object is an element that is used to access the properties of the class in which or for which it is created.

Syntax,

<classname> <objectname>;

Example,

sum   s1;

In above example, we have created the object namely s1 of class sum that we have created  in previous example . Now with the help of  s1 , we can access the property of class sum.

class and encapsulation
class and encapsulation

Encapsulation:-

The process of creating a class is known  as Encapsulation.In other words we can say that,”The process of wrapping up of data and its associated function together into a single unit  (called class) is know as an  Encapsulation.

Example:-

class area

{

int a,b;

public:

void putdata (int x, int y)

{

a=x;

b=y;

}

void  getarea ()

{

int area=a*b;

cout<<”/n Area  Of A Rectangle  Is:-“<<area;

}

};

void main()

{

clrscr();

area a;

a.putdata(3,5);

a.getarea();

getch();

}

Output:-

Area  Of A Rectangle  Is:-15

Explaination Of Above Program,

First of all we have created a class namely ‘area’, after that I have declared variables  namely a,b.Now  I have specified access specifier ‘public’ since we want to access following  function namely ‘putdata()’ publically.In this function I have put the value of variable x,y into variables a,b.

After that I have created  a function namely ‘getarea()’ in which we are calculating area and displaying it with the help of an Built-In Object namely ‘cout’ .

Now in main() function I am creating an Object of class by following statement,

area a;

Now I am calling the function putdata() and getarea() with the help ofobject ‘a’ that we have created earlier.

So its all about the concept of ‘class and encapsulation in c++’.

My Words:-

I know you will like this post very much.After getting it in your mind please tell me, how it was? Like this post I will provide all stuff like Computer Science , Mathematics , Technology  , Meditation etc.

You Also Can See More Result By Using Google Search.

You Also Can Play Online Quiz by following Link,

Computer Science

You Also Can Ask and Give Answer of Questions by following Link,

Questions

If you have any requirements to know more about it in detail, then this content may be helpful to you.

You Also Can Visit For More Knowledge In C++:-

Visit Your YouTube  Channel:-  Think , About It

Visit Your Website :- www.atozlives.com

Thanks,

“Play With All Computer Science , Mathematics  And Technology.”

 

 

36 COMMENTS

  1. Thanks for another excellent article. Where else could anybody get that type of info in such a perfect way of writing? I’ve a presentation next week, and I am on the look for such information.

  2. Needed to compose you the bit of word so as to say thanks a lot as before for the spectacular principles you have contributed on this site. This has been certainly tremendously open-handed of people like you in giving publicly what exactly many individuals might have offered for sale for an e-book to generate some bucks for their own end, specifically now that you could have done it in case you desired. The solutions as well acted like the easy way to realize that many people have the identical fervor just like my very own to know the truth a little more with regards to this problem. I am sure there are thousands of more pleasant moments ahead for people who scan your site.

  3. I and my buddies have been digesting the excellent solutions located on the website then instantly got a terrible suspicion I never thanked the site owner for those tips. My young men are already totally excited to read them and already have seriously been making the most of those things. Appreciate your genuinely quite helpful and also for utilizing some outstanding themes most people are really desirous to understand about. My honest apologies for not expressing appreciation to you sooner.

  4. I intended to write you one very little observation to finally give thanks yet again regarding the lovely things you’ve shown above. It has been certainly incredibly open-handed with people like you to convey freely all that a few individuals might have made available as an e book in making some profit on their own, chiefly given that you might well have done it if you decided. Those ideas in addition acted as the easy way to understand that some people have similar passion like my very own to understand more when it comes to this condition. I’m certain there are lots of more pleasurable situations in the future for individuals that scan your blog.

  5. I precisely wished to appreciate you all over again. I do not know the things that I would’ve carried out without the type of creative ideas discussed by you relating to that topic. It had become the frustrating matter in my opinion, but taking a look at your professional style you managed that made me to leap over joy. I’m just grateful for your assistance and wish you really know what a powerful job you are always providing teaching the others through your blog post. I know that you’ve never met any of us.

  6. Thanks a lot for providing individuals with such a splendid chance to read from here. It’s usually very pleasant and full of fun for me and my office fellow workers to visit the blog at the least 3 times in one week to read the new issues you have. And indeed, I am certainly amazed with the wonderful techniques you give. Selected 3 areas in this posting are honestly the most suitable I have had.

  7. I intended to draft you a little bit of word to say thanks a lot over again for your amazing basics you’ve discussed above. This has been certainly open-handed of people like you to offer easily all that a lot of people would’ve advertised for an e book in making some cash for themselves, even more so considering the fact that you might well have done it in case you decided. The tactics in addition served to be a fantastic way to realize that someone else have the identical zeal similar to my personal own to figure out more with regard to this issue. I’m sure there are lots of more fun moments up front for folks who find out your blog.

  8. I would like to get across my affection for your kind-heartedness giving support to women who really need guidance on your concern. Your very own commitment to passing the solution around came to be unbelievably functional and have specifically helped those like me to arrive at their aims. This helpful recommendations denotes this much a person like me and somewhat more to my fellow workers. Thank you; from each one of us.

  9. Thanks a lot for providing individuals with an extremely memorable possiblity to check tips from here. It can be so fantastic plus packed with a great time for me and my office colleagues to visit the blog the equivalent of thrice in one week to learn the newest tips you have. Of course, I’m certainly pleased considering the staggering pointers served by you. Certain 1 points in this posting are definitely the most effective I’ve ever had.

  10. I simply wanted to send a small message in order to appreciate you for some of the unique advice you are giving out at this site. My time consuming internet investigation has now been compensated with professional concept to share with my family and friends. I would mention that many of us site visitors actually are undeniably blessed to live in a perfect place with so many perfect individuals with good hints. I feel very much blessed to have seen your site and look forward to many more excellent moments reading here. Thank you again for a lot of things.

  11. I must show thanks to the writer just for rescuing me from this scenario. Because of looking out through the internet and getting notions which are not helpful, I assumed my entire life was done. Being alive without the presence of strategies to the difficulties you have resolved by way of your good posting is a serious case, as well as those which may have in a wrong way affected my entire career if I hadn’t encountered your web blog. Your own personal competence and kindness in dealing with every part was excellent. I am not sure what I would’ve done if I hadn’t come across such a stuff like this. I can also at this time look forward to my future. Thanks for your time very much for the high quality and effective guide. I will not hesitate to propose your site to anybody who desires recommendations on this area.

  12. I precisely desired to say thanks once again. I’m not certain the things that I might have taken care of without the techniques shown by you directly on my problem. It was actually a frustrating circumstance for me, however , discovering a skilled manner you handled that made me to leap for contentment. I will be grateful for your guidance and thus sincerely hope you find out what an amazing job you are getting into training people today all through your websites. I know that you haven’t encountered all of us.

  13. I truly wanted to write a small message in order to appreciate you for all of the superb secrets you are giving out at this site. My time consuming internet investigation has now been honored with excellent facts to talk about with my two friends. I ‘d believe that we readers actually are rather lucky to live in a useful place with very many wonderful individuals with very beneficial basics. I feel very much privileged to have seen your entire website page and look forward to really more pleasurable moments reading here. Thanks a lot once more for everything.

  14. Needed to create you that bit of remark to finally say thank you as before for the extraordinary suggestions you have provided on this site. It’s really remarkably open-handed of people like you to provide freely precisely what many people would have supplied for an ebook to end up making some bucks for themselves, most importantly considering the fact that you might have done it in the event you wanted. These good ideas as well worked as the great way to realize that someone else have a similar desire really like my personal own to figure out way more on the subject of this matter. I know there are a lot more pleasurable periods ahead for individuals who discover your site.

  15. I needed to compose you that little bit of observation to be able to thank you very much once again for your personal splendid guidelines you’ve documented on this website. This is really unbelievably open-handed of people like you to present freely all most people would have advertised for an ebook to earn some cash for their own end, principally since you might have tried it in case you decided. Those secrets as well served to become a good way to fully grasp that other people have similar dream the same as my own to learn a little more on the topic of this issue. I am sure there are some more pleasant opportunities up front for folks who read your website.

  16. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
    You clearly know what youre talking about, why throw away your intelligence on just posting videos to your
    blog when you could be giving us something informative to read?

  17. Having read this I believed it was very informative.
    I appreciate you spending some time and energy to put this content together.
    I once again find myself personally spending a significant amount of time both reading
    and posting comments. But so what, it was still worth
    it!

  18. I’m amazed, I have to admit. Seldom do I encounter a blog
    that’s equally educative and engaging, and without a doubt, you’ve hit the nail on the head.
    The problem is an issue that not enough people are speaking intelligently
    about. I’m very happy that I stumbled across this in my hunt for something regarding this.

  19. I would like to show some thanks to this writer for bailing me out of such a setting. Because of looking out through the world-wide-web and meeting tips that were not helpful, I thought my entire life was well over. Living devoid of the approaches to the difficulties you’ve solved all through your main posting is a serious case, as well as the kind that would have in a negative way damaged my career if I hadn’t noticed your blog post. That competence and kindness in dealing with all areas was tremendous. I am not sure what I would have done if I hadn’t come across such a point like this. It’s possible to now relish my future. Thanks very much for the skilled and result oriented help. I will not think twice to suggest your web site to any person who should get care about this matter.

  20. I wanted to put you this tiny observation just to say thanks the moment again about the fantastic information you have discussed on this website. This is open-handed of you giving publicly what numerous people could possibly have offered for sale as an e-book in order to make some profit for their own end, principally seeing that you could have done it if you considered necessary. Those basics additionally acted to be a easy way to be sure that the rest have similar zeal similar to my own to learn much more in regard to this issue. I’m certain there are many more fun situations in the future for individuals that scan through your site.

  21. My spouse and i were so excited Louis could round up his web research through your ideas he discovered using your weblog. It is now and again perplexing to simply always be giving away techniques other people might have been trying to sell. And we fully grasp we need you to give thanks to because of that. The explanations you’ve made, the simple site navigation, the friendships you can help foster – it is most powerful, and it’s aiding our son and us consider that that article is cool, and that’s pretty essential. Many thanks for the whole lot!

  22. I must express my thanks to you for rescuing me from such a matter. After checking throughout the the web and seeing solutions which were not helpful, I believed my life was well over. Living devoid of the strategies to the difficulties you’ve sorted out by means of your main guide is a serious case, as well as the ones that could have adversely damaged my entire career if I had not encountered your blog. Your primary natural talent and kindness in taking care of every aspect was tremendous. I am not sure what I would have done if I hadn’t encountered such a thing like this. I can also at this point look ahead to my future. Thanks so much for the reliable and sensible help. I won’t think twice to endorse your web page to anyone who should receive care on this subject matter.

  23. I really wanted to jot down a small message to be able to thank you for these magnificent tips and hints you are giving out at this website. My time-consuming internet look up has at the end been rewarded with reputable facts and techniques to go over with my visitors. I would admit that many of us readers actually are unequivocally endowed to be in a remarkable place with very many marvellous individuals with valuable tactics. I feel very much grateful to have seen your webpage and look forward to many more pleasurable minutes reading here. Thanks once again for all the details.

  24. I simply had to appreciate you again. I am not sure the things that I would’ve taken care of in the absence of the tricks documented by you regarding that situation. It was before a real depressing scenario in my position, nevertheless spending time with this professional avenue you solved it forced me to cry for contentment. I am grateful for this work and then hope you recognize what a great job you were doing training the mediocre ones all through your webblog. I know that you haven’t met all of us.

  25. I precisely needed to thank you so much yet again. I do not know what I would’ve worked on without the entire concepts discussed by you about such question. Entirely was an absolute frightening crisis in my circumstances, nevertheless finding out your professional avenue you processed the issue took me to jump with contentment. I’m happier for this information and even sincerely hope you comprehend what a powerful job you have been putting in educating others using a web site. Most probably you haven’t come across all of us.

  26. I would like to express some appreciation to the writer just for rescuing me from this scenario. As a result of scouting through the internet and meeting ways that were not beneficial, I figured my entire life was well over. Existing devoid of the strategies to the issues you have solved as a result of your good review is a critical case, and those that might have in a wrong way affected my career if I had not discovered your web blog. Your own training and kindness in controlling all the things was crucial. I don’t know what I would have done if I hadn’t encountered such a point like this. It’s possible to at this moment look forward to my future. Thanks for your time so much for your impressive and effective help. I won’t think twice to endorse your blog post to any individual who should get direction on this matter.

  27. A formidable share, I just given this onto a colleague who was doing slightly evaluation on this. And he in truth purchased me breakfast because I discovered it for him.. smile. So let me reword that: Thnx for the deal with! But yeah Thnkx for spending the time to discuss this, I really feel strongly about it and love studying extra on this topic. If potential, as you change into expertise, would you mind updating your blog with more particulars? It is extremely helpful for me. Big thumb up for this weblog submit!

  28. The following time I learn a blog, I hope that it doesnt disappoint me as a lot as this one. I mean, I know it was my option to read, but I really thought youd have one thing fascinating to say. All I hear is a bunch of whining about one thing that you might repair if you werent too busy on the lookout for attention.

  29. I used to be very happy to find this web-site.I needed to thanks to your time for this excellent learn!! I undoubtedly enjoying every little bit of it and I’ve you bookmarked to take a look at new stuff you weblog post.

  30. My wife and i got delighted when Emmanuel managed to conclude his inquiry while using the precious recommendations he made from your web pages. It is now and again perplexing to simply choose to be releasing techniques that others could have been making money from. Therefore we see we have the website owner to give thanks to because of that. The illustrations you’ve made, the simple website navigation, the friendships your site assist to create – it’s got everything astonishing, and it is letting our son and the family consider that the topic is satisfying, which is incredibly vital. Thanks for everything!

  31. I have to express some thanks to this writer just for rescuing me from this scenario. After exploring throughout the the web and finding suggestions which are not helpful, I thought my life was well over. Existing devoid of the strategies to the problems you have fixed by way of your entire guide is a critical case, and ones which might have badly affected my entire career if I hadn’t come across your web blog. Your actual expertise and kindness in handling all the stuff was invaluable. I am not sure what I would’ve done if I had not encountered such a point like this. It’s possible to now look forward to my future. Thank you very much for this reliable and effective help. I won’t think twice to endorse your blog to any individual who needs guidance about this problem.

LEAVE A REPLY

Please enter your comment!
Please enter your name here