+ 3

What's the difference between protected and public ?

21st Mar 2018, 10:44 AM
rishabh
rishabh - avatar
3 odpowiedzi
+ 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.
21st Mar 2018, 11:12 AM
apex137
apex137 - avatar
+ 4
Protected : classes within the same package can access data. Public : Any class can access data.
21st Mar 2018, 12:10 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 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.
24th Mar 2018, 6:39 AM
AKASH CP
AKASH CP - avatar