Question: Consider the following extract from a program: 1 c l a s s Shape 2 { 3 public : 4 Shape ( ) ; 5

Consider the following extract from a program:
1 c l a s s Shape
2{
3 public :
4 Shape () ;
5 void s e t S i z e ( int ) ;
6 v i rtua l void draw ()=0 ;
7 protected :
8 int s i z e ;
9} ;
10 c l a s s Square : public Shape
11{
12 public :
13 void draw () ;
14} ;
15 c l a s s Line : public Shape
16{
17 public :
18 bool draw () ;
19} ;
(a) Waarom word draw() in die Shape klas virtual verklaar? Wat beteken dit?
Why is draw() in the Shape class declared virtual? What does it mean?
Skep vtable, maak polimorfisme moontlik, sodat basisklas pointer na afgeleide
klas objek afgeleide klas impl kan sien (3)
(b) Watter draw() implementering sou geroep word as n Shape pointer na n Square objek
gebruik word om draw() te roep? Motiveer.
Which draw() implementation would be called when a Shape pointer to a Square object
was used to call draw()? Motivate.
Afgeleide klas, virtual in basisklas en signature stem ooreen in afgeleide klas (4)
(c) Watter draw() implementering sou geroep word as n Shape pointer na n Line objek
gebruik word om draw() te roep? Motiveer.
Which draw() implementation would be called when a Shape pointer to a Line object
was used to call draw()? Motivate.
Geen: Basisklas is suiwer, geen impl, en afgeleide klas het nie n void draw
nie. Fout kom voor wanneer Line objek gemaak word.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!