Exam4Training

b?

Which code, inserted at line 8, generates the output "0102020"?

#include <iostream>

using namespace std;

class Base {

static int age;

public:

Base () {};

~Base () {};

//insert code here

void Print() { cout << age;}

};

int Base::age=0;

int main () {

Base a,*b;

b = new Base();

a.Print();

a.setAge(10);

a.Print();

b?>setAge();

a.Print();

b?>Print();

return 0;

}
A . void setAge(int a) {age = a;}
B . void setAge() {age = 20;}
C . void setAge() {age = 10;}
D . void setAge(int a=20) {age = a;}

Answer: D

Exit mobile version