Describe PRIVATE, PROTECTED And PUBLIC ? The Differences And Give Examples.

Describe PRIVATE, PROTECTED And PUBLIC ? The Differences And Give Examples.


  • 12 Dec, 2011

    class Point2D{int x; int y;public int color;protected bool pinned;public Point2D() : x(0) , y(0) {} //default (no argument) constructor};Point2D MyPoint;You cannot directly access private data members when they are declared (implicitly) private:MyPoint.x = 5; // Compiler will issue a compile ERROR//Nor yoy can see them:int x_dim = MyPoint.x; // Compiler will issue a compile ERROROn the other hand, you can assign and read the public data members:MyPoint.color = 255; // no problemint col = MyPoint.color; // no problemWith protected data members you can read them but not write them: MyPoint.pinned = true; // Compiler will issue a compile ERRORbool isPinned = MyPoint.pinned; // no problem

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.