Private or Public?

I just wanted to know a dumb-down version of the difference between the two Private or Public within writing C++/C# code?
One allows member access outside of member function, the other doesn't.
Surely the source who told you that those two existed also told you what they meant?
They are as private and public correspondences.:)
@Athar yeah it does explained in a book that I have been reading and practicing typing C# code with the book is McGraw-Hill ISBN 978-0-07-158830-0, I'm a newbie so just learning a lot of this stuff. My reason for programming is to create applications and program PCB's to do certain things would this be a good language to begin with???
In a nutshell:

A class separates the world into three pieces: things that are that class, things that are not, and things that are somewhere between.

For example, suppose we have a class like this:

    class point
    {
      double x, y;
    };

If I create a point like this: point pt;, then pt is an instance of the point type.

If I inherit from a point, I get another thing that both is and isn't a point.

So, the question is, who gets to see and play with the x and y members?

public:
Anyone.

protected:
Only points and objects that inherit from points.

private:
Only points.


A very simple rule of thumb might be: You should design your classes so that you only hide things in order to prevent outside stuff from breaking it.

Hope this helps.
Last edited on
Topic archived. No new replies allowed.