Given the following class, which function is used to initialize the data members
ID: 3823088 • Letter: G
Question
Given the following class, which function is used to initialize the data members when an instance of the object is declared? (C++)
class myClass
{
private:
int x, y;
public:
myClass();
void setValues(int _x, int _y) { x=_x; y=_y; };
int getX() { return x; };
int getY() { return y; };
};
A.) int getY() { return y; };
void setValues(int _x, int _y) { x=_x; y=_y; };
int getX() { return x; };
D.) myClass();
B.)void setValues(int _x, int _y) { x=_x; y=_y; };
C.)int getX() { return x; };
D.) myClass();
Explanation / Answer
Ans)void setValues(int _x, int _y) { x=_x; y=_y; };
here With this function we can initialize the data memebers.When we call this function by using the Class instance.by passing the values as arguments.then those values will be initialized to the class instance variables.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.