Help needed

Hi, I needed some help to confirm my answers.
Please help me check whether my answers are correct. Thank you.

Question 1.

class B1
{ ??????? class no_B1;

private:
int b;
};

class no_B1
{
private:
B1 x;
public:
no_B1 (int y)
{
x.b = y;
}
void display()
{
cout << x.b << endl;
}
};
int main()
{
no_B1 b1(6);
b1.display();
}

answers:
1) static
2) public
3) friend
4) global

My answer is 3(friend). Am I correct?


Question 2.

A C++ object is an instantiation of a class that can contain both ____ and ____

answers:
i. variable
ii. data members
iii. methods
iv. field

1) All of the above
2) i & iv only
3) ii & iii only
4) None of the above

My answer is 3(data members & methods) Am I correct?


Question 3.

class B
{
private:
static int b;
public:
B()
{
b = 2;
}
void setB(int b)
{
this ->b = b;
}

int getB()
{
return b;
}
};

int main()
{
B theB;
theB.setB(4);
cout << theB.getB() << endl;
}

answers:
1) The output is 2
2) The output is 4
3) The instance member function can access the static data member, b
4) The static data member needs to be declared at the implementation section

My answer is 2(The output is 4) Am I correct?

Thank you.


Last edited on
closed account (o3hC5Di1)
Hi there,

Please don't ask us to correct our homework, that could be considered as cheating.
That being said, I suggest you read some of the links on this page: https://www.google.com/search?q=c%2B%2B%20static%20data%20member

All the best,
NwN
Topic archived. No new replies allowed.