Best Answer

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.

User Avatar

Wiki User

โˆ™ 2012-07-24 16:27:03
This answer is:
User Avatar
Study guides

What is a programming language

What does DOS stand for

What is a software that is distributed for free

What is application software

See all cards
32 Reviews

Add your answer:

Earn +20 pts
Q: How can a value from the derived class be assigned to a variable in base class?
Write your answer...
Still have questions?
magnify glass
Related questions

Can a double value be assigned to a float value?

No, but a double value can be assigned to a float variable. (You will lose from the precision, obviously.)

What are the difference between private variable and final variable?

A private variable is one that is accessible only to the current class and cannot be accessed by any other class, including the ones that extend from it. A final variable is one that cannot be modified once it is initialized and assigned a value.

What is used as placeholder for an assigned value in a computer memory?


What value is assigned to extern variable?

Default initial value of extern integral type variable is zero otherwise null.

How do you use define in C?

Just type declare then the variable that you desire to assigned a certain constant value on it. Just type declare then the variable that you desire to assigned a certain constant value on it.

What is an expression with one variable?

3x+2 x is a variable. A variable is a symbol (x, y, etc...) that does not have an assigned value.

What Is similar to a variable except it can be assigned a value only once?

A constant.

Can an int value be assigned to String variable?

In C when assigning an integer variable to String variable a compilation error occurs as Incompatible Type Conversion.So that integers cannot get assigned to String variables.

What is the definition of constant variable?

The definition of constant variable is a variable whose value cannot be changed once it has been assigned a value for an experiment. It is the variable held steady, or constant, for a specific experiment.

What is the decimal value of the letter u?

None. A letter has no numerical value unless it represents a variable and a value is assigned to it.

Difference between preincrementing a variable and postincrementing a variable?

Both increment the value of the variable by one. The difference is the value of the increments expression itself. With preincrement value is taken after incrementing, and with postincrement value is taken before incrementing. Example: Let x have value 5. y = ++x; Both y and x are assigned value 6. Again let x have value 5. y = x++; y is assigned value 5. x is assigned value 6.

How do you assign values to variables?

it depend on the programming language u use. for instance in c, just decalre the variable and equal it to the value it is to take. eg. my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ //for php $my_age=21; /*my_age is the decared variable and 21 is the assigned value*/ for strings (in php)eg. $my_age="none of ur business" /*$my_age is the variable and the string "none of ur business" is the assigned value*/

People also asked