Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
3.5k views
in Computer by (64.1k points)

Differentiate between public and protected visibility in context of Object Oriented Programming giving suitable examples for each.

1 Answer

+2 votes
by (69.4k points)
selected by
 
Best answer
Public visibility Protected visibility
The public derivation means that the derived class can access the public and protected members of the base class but not the private members of the base class. The protected derivation means that the derived class can access the public and private members of the base class protectedly.
With publicly derived class, the public members of the base class become the public members of the derived class, and the protected members of the base class become the protected members of the derived class. With protectedly derived class, the public and protected members of the base class become protected members of the derived class.
Example:
class super
{
private:
int x; void get();
public:
int y; void put();
protected:
int z; void disp();
};
class sub:public super
{
private:
int a; void init();
public:
int b; void readit();
protected:
int c; void writeit();
};
Example:
class super
{
private: int x;
void get();
public: int y;
void put();
protected: int z;
void disp();
};
class sub:protected super
{
private:
int a; void init();

public:
int b; void readit();
protected:
int c; void writeit();
};

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...