Ask Question
31 May, 11:20

class bClass{public:void setX (int a); //Postcondition: x = a; void print () const; private:int x; }; class dClass: public bClass{public:void setXY (int a, int b); //Postcondition: x = a; y = b; void print () const; private:int y; }; Which of the following correctly sets the values of x and y? a. void dClass::setXY (int a, int b) {x = bClass. setX (a); b = y; }b. void dClass::setXY (int a, int b) {x = bClass::setX (a); y = bClass::setY (b); }c. void dClass::setXY (int a, int b) {x = a; y = b; }d. void dClass::setXY (int a, int b) {bClass::setX (a); y = b; }

+2
Answers (1)
  1. 31 May, 14:13
    0
    The answer to the given question in the option "a".

    Explanation:

    In the given c+ + program the correct sets value of x and y is option a:

    void dClass::setXY (int a, int b) / /function implementation

    { / /function body.

    x = bClass. setX (a); / /variable x hold value of setX () function.

    b = y; / /variable b holds value of y.

    }

    And other option are not correct that can be described as:

    In option b, x is private variable of the base class that is inherit by the derived class but variable y is not part of the base class. that's why it is wrong. In option c, x = a is correct but y=b is not correct. that's why it is wrong. In option d we access the value of the private variable x that is a part of the base class but in this we not use any variable that holds its value. that's why it is wrong.

    So the answer to this question is the option "a".
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “class bClass{public:void setX (int a); //Postcondition: x = a; void print () const; private:int x; }; class dClass: public ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers