Compared with the classes from which they are derived, inherited classes may have _____

additional data members
additional member functions
both (a) and (b)
neither (a) nor (b)

The correct answer is C. both (a) and (b).

When a class inherits from another class, it gains access to all of the data members and member functions of the base class. It can also add its own data members and member functions. This means that an inherited class can have more data members and member functions than the base class.

For example, consider the following code:

“`class Base {
public:
int x;
void foo() {
cout << “Base::foo()” << endl;
}
};

class Derived : public Base {
public:
int y;
void bar() {
cout << “Derived::bar()” << endl;
}
};
“`

The class Derived inherits from the class Base. This means that Derived has all of the data members and member functions of Base, plus its own data member y and member function bar().

In conclusion, inherited classes may have additional data members and member functions compared with the classes from which they are derived.

Exit mobile version