inheritance doodling program and i couldn't get it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

inheritance doodling program and i couldn't get it

https://www.sololearn.com/compiler-playground/cSBjV9lFN3jJ d.draw(); (line 37) this code line can also solve this problem but code coach's solution was diffrent (the thing i left uncommented in program) Shape sh; (line 34) sh.draw(); And also what does this sh mean ( we didn't declare it before)

17th Dec 2022, 5:29 PM
Lalala
Lalala - avatar
1 Answer
0
The drawing with the derived class, d.draw(), using the draw method of its base is the basic idea of inheritance. The solution it shows completely side steps the idea of showing inheritance as the base class calls the function itself. Thus making the rectangle declaration a waste of space, as the solution never uses it. Now if the solution showed both drawing, maybe it could be said that it was showing how both classes could call the draw method but how it is, doesn't really do that.
17th Dec 2022, 8:50 PM
Bloody Halos
Bloody Halos - avatar