Need it in C++ 4.P.822, Problem 10 (20 pts) 10. A class called Derivedclass is a
ID: 3710248 • Letter: N
Question
Need it in C++
4.P.822, Problem 10 (20 pts) 10. A class called Derivedclass is a subclass of a class called BaseClass. DerivedClass also has a member field that is an object of class ComposedClass. a. Which class's constructor is called first when an object of class DerivedClass is created? Which class's constructor is called last when an object of class Derivedclass is cre- ated? b. 5.?.824, Problem 12 (20 pts) 12. What's wrong with the following class declarations? class BaseClass public: virtual void BaseAlpha ; private: float baseField; class DerivedClass: public BaseClass public: virtual void BaseAlpha ): private: int derivedField;Explanation / Answer
// SOlution 10
a ) first the child(derived) class constructor is called .
when a child called it constructor , The child class constructor always implicitly calls its super class constructor at the 1st line of the constructor block. so 1st child class constructor is called first then it recusively call it super class constructor.Then it ll do any initialization job.
b ) the "Composed" class constuctor is called last. when derived class constructor is get called .it will call the super class after that it will initialize its members.at that time it need to call the constructor of Compoed class.
// SOlution 12
=> BaseAlpha() method is already decalred virtual in base class.
It cannot be declared virtual again in Derived class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.