+ 3
What's the difference between protected and public ?
3 Answers
+ 4
Protected means that a derived class can access the private members of its parent class. Public means that it can be accessed from anywhere within the program.
+ 4
Protected : classes within the same package can access data.
Public : Any class can access data.
+ 4
PUBLIC;
A data member of a class that is given public,can be accessed by any of the function of its own class or any other class .on coming to inheritance the public data member of a base class will be also public in its derived class, that is it can be accessed by any function on the program.
PROTECTED;
when a data member is declare inside a class as protected then it can be accessed only by the functions of the same class or by the next first derived class, of the base class. on coming to inheritance the, if the inheritance is by public, then protected data members of the base class behave as protected, if the inheritance is by private then the protected data member behave as private in the derived class.