Lecture 21 Flashcards
1
Q
Polymorphism is
A
one of the central ideas of object-orientation (OO): that a single object may take on multiple different roles within a program.
2
Q
The word originates from Greek,
meaning
A
– “poly”: many
– “morph”: forms
3
Q
class Shape { public: virtual double area() = 0; virtual double perimeter() = 0; } //=0 does what?
A
The “= 0” on each method indicates that our class Shape does not define the method – it is the responsibility of any class fulfilling this role to implement them instead.
4
Q
class Shape { public: virtual double area() = 0; virtual double perimeter() = 0; } //virtual means what?
A
The keyword “virtual” on the methods indicates that
Shape expects implementing classes to provide their own
definition, and will allow those to be accessed from the
Shape perspective.
5
Q
class Circle: public Shape { public: Circle(double r); double area(); double perimeter(); void draw(); private: double radius; } //public shape allows what?
A
public shape-indicates that
Circle is inheriting the specifications and
preexisting blueprint of the type Shape.
public indicates that the original access
modifiers of Shape should remain
unchanged.