Computer Programming
Java Programming
C++ Programming

How can a value from the derived class be assigned to a variable in base class?

User Avatar
Wiki User
July 24, 2012 4:27PM

Remember that derived classes can access the public and protected members of their base class, but none of the private members. If the member variable in the base class is protected (rather than private), then the derived class can assign it directly. However, this is bad style in OOP as it undermines data-hiding. A protected mutator (set accessor) would be a better option.