In the following example s the base class? Which is the derived class? Which bas
ID: 3833446 • Letter: I
Question
In the following example s the base class? Which is the derived class? Which base class members the derived class can access directly? Which base class members the derived class can not access directly? class ABC {public: ABC(int = 10, int = 5) void funcx(); void funcy(); void funcz (); private: int x; int y;}; class XYZ: public ABC {public: void func3(); void func4(); private float w; float s;}; List the data members of class ABC and class XYZ. Write the function headers only for defining the member functions of the class ABC and class XYZ.Explanation / Answer
A derived class is a class created or derived from another existing class. The existing class from which the derived class is created through the process of inheritance is known as a base class or superclass.
A base class which contains the properties of its own while the derived class contains the properties of its own as well as the properties of its parent class.
like child and parent relations
parent is the base class and child is the derived class.
in the above example, the base class is class ABC
class ABC{
public:
ABC(){
x=10;
y=5;
}
void funcx();
void funcy();
void funcz();
private:
int x;
int y;
};
the derived class is:-
class XYZ: public ABC{
public:
void func3();
void func4();
private:
float w;
float s;
};
the public data members of the class can be accessed directly anywhere in the class as well as in dervied class while the private data members can only accessible to its own class. It doesnt matters whether it is child class or parent class.
A) data memebers of class ABC:-
int x;
int y;
data members of class XYZ :-
float w;
float s;
B) member functions of class ABC:-
void funcx();
void funcy();
void funcz();
memeber functions of class XYZ: -
void func3();
void func4();
since the functions body will define the properties of data members.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.