1. Select the derived class method definitions that represent actual method chai
ID: 3842297 • Letter: 1
Question
1.
Select the derived class method definitions that represent actual method chaining (never mind the reason or effect, as long as it demonstrates a derived class method chaining to a base class method). There is more than one correct answer.
2.. Consider the following code fragment (assumed to be in an otherwise correct program):
Assume there are no omitted statements within this fragment -- you see everything. Check the true statements (may be more than one):
Illegally attempts to delete non-dynamic memory.
A. string SubClass::toString(string msg) { return BaseClass::toString(msg) + " hi dad."; } B. string SubClass::toString() { return BaseClass::toString("My Message ----") + " hi dad."; } C. void SubClass::methodTwo(int a) { BaseClass::methodTwo(4); // calling int-parameter method // other stuff } D. BaseClass::methodTwo(int a) : BaseClass::methodTwo(a) { // other stuff } E. SubClass::methodTwo(int a) { BaseClass::methodOne(a); // other stuff }
Explanation / Answer
A. is true
Explanation:
A is true because we are trying to call Base Class toString with parameters hence both should be parameterized
C is true because mthod has return type as void and we call baseClass function inside it
A .It will compile without error but probably crash (i.e., generate a run-time error).
C. It has an array bounds violation, possibly causing a fatal runtime error.
Explanation:
Below two statements are correct, Compilation will go successfully but there can be run time error as we are trying to access beyond buffer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.