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)
1 Odpowiedź
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.