+ 2

Can class in c++ be public private and protected??

10th Aug 2019, 6:28 AM
Neha Kumar
Neha Kumar - avatar
3 Answers
+ 4
No it cant be as per my knowledge
10th Aug 2019, 6:29 AM
Akash
Akash - avatar
+ 4
Yes they can if they are inside another class.. For example iterator of std::vector is a public class inside the vector class from the C++ Standard Template Library. If you need you can define a private class inside a class, obviously it could become a complicated system.
11th Aug 2019, 12:30 AM
AZTECCO
AZTECCO - avatar
+ 1
Do you mean if a class can be public private and protected all at the same time, then no it isn't possible, but if you are asking if classes can have access specifiers in c++ then yes it does. class A { private: // Private members public: // Public members protected: // Protected members }; In inheritance an entire class can have access specifiers For example Class A: public B { // Same for other specifiers }
10th Aug 2019, 8:05 AM
RZK 022
RZK 022 - avatar