August 1997
OP216: OBJECT ORIENTED PROGRAMMING

QUESTION 3

Total Marks: 20 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 3

3. (a) Polymorphism is an important characteristic of object-oriented programming; it can be defined in C++ using virtual functions. Define a virtual function example that takes an integer parameter and returns void. [3]
(b) The use of virtual functions allows dynamic binding. Explain what is meant by dynamic binding and explain how it is different from static binding. [4]
(c) State one advantage and one disadvantage of dynamic binding. [2]
(d) What is a friend function? [2]
(e) In the context of friend functions, give a reasoned answer to the following questions.
(i) if Dog class is a friend of Boy class, is Boy a friend of Dog? [3]
(ii) if Dog is a friend of Boy, and Terrier derives from Dog, is Terrier a friend of Boy? [3]
(iii) if Dog is a friend of Boy, and Boy is a friend of House, is Dog a friend of House? [3]