9618/31 October/November 2022 · Question 11 · 8 marks
(a) Define these OOP terms: instance, inheritance, polymorphism. (b) Complete the pseudocode for the class Car to enable objects to be created: string attributes for the make, model, body type and fuel type, and an integer attribute for the number of cars of that type built. The attributes must be available only through the methods of the class.
Points that gain marks
- (a) Instance: an occurrence of an object; a specific object based on the class.
- Inheritance: defining a new class of objects that has all the attributes and methods of the parent class.
- Polymorphism: the same method takes on different behaviours depending on the class; methods can be redefined for derived classes.
- (b) CLASS Car and ENDCLASS.
- Four PRIVATE declarations, using the identifiers in the assignments.
- A constructor header that uses CarBodyType.
- Two assignments, using CarMake.
- The same identifier for the car model in the constructor and in the Model assignment.
In this lab: Level 5 is part (b); level 6 uses the definitions.