0% found this document useful (0 votes)
162 views6 pages

Combined IB CS Paper2 OptionD

Uploaded by

Enes Artan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views6 pages

Combined IB CS Paper2 OptionD

Uploaded by

Enes Artan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

IB Computer Science Paper 2 (HL) - Option D: Object-Oriented Programming

---

### Question 14 (a)

**Question:**

Outline the general nature of an object. [2]

**Mark Scheme:**

- Award [2 max].

- An object is an abstract entity;

- Consists of data/attributes/properties;

- Has methods/behaviour/actions on that data/attributes/properties;

- An object occupies memory/has a lifecycle;

- An object is an instance of a class.

---

### Question 14 (b)

**Question:**

State one mutator method to be included in the class Rental. [1]

**Mark Scheme:**

- Award [1 max].

- Any instance variable with the prefix 'set' such as:

- setNumberPlate(String numberPlate);
- setPricePerDay(double pricePerDay);

- setRentalClass(char rentalClass);

- setYear(int year);

- SetBrandModel(String brandModel);

- SetFuelType(boolean fuelType);

- SetTransmissionType(boolean transmissionType).

- Note: Ignore the parameter and semicolon.

---

### Question 14 (c)

**Question:**

Construct the code for the accessor method getBrandModel(). [3]

**Mark Scheme:**

- Award [3 max].

- public method;

- return type;

- correct return (keyword 'this' is not required).

Example answer:

public String getBrandModel()

return this.brandModel;

---
### Question 14 (d)

**Question:**

Outline one purpose of a default constructor. [2]

**Mark Scheme:**

- Award [2 max].

- A default constructor instantiates an object of a class;

- With null or default values for instance variables/attributes;

- Without using any parameters.

---

### Question 14 (e)

**Question:**

Outline one change that needs to be made to the class Rental due to the development of new

electric cars and hybrid cars. [2]

**Mark Scheme:**

- Award [2 max].

- fuelType can no longer be a boolean;

- Could be another datatype such as int, char, or String to represent different fuel types.

---

### Question 14 (f)

**Question:**
State the relationship between Rental and Car. [1]

**Mark Scheme:**

- Award [1 max].

- Car inherits Rental (allow "Car is a Rental" or "Car extends Rental" or "Car is a subclass of

Rental").

---

### Question 14 (g)

**Question:**

Construct the code for the class Car without duplicating the attributes and methods from the class

Rental. The default constructor of the class Rental should be overridden to assign the value 4 to

numberOfDoors. No other constructors are required. [3]

**Mark Scheme:**

- Award [3 max].

- [1] for public class Car extends Rental;

- [1] for declaring numberOfDoors;

- [1] for numberOfDoors being set to 4 within the constructor.

Example answer:

public class Car extends Rental

private int numberOfDoors;

public Car()
{

this.numberOfDoors = 4;

public int getNumberOfDoors()

return this.numberOfDoors;

public void setNumberOfDoors(int n)

this.numberOfDoors = n;

---

### Question 15 (a)

**Question:**

Identify the OOP feature that was used to declare the Car class. [1]

**Mark Scheme:**

- Award [1 max].

- Inheritance.

---
### Question 15 (b)

**Question:**

Explain the benefits of the feature identified in part (a). [3]

**Mark Scheme:**

- Award [3 max].

- The parent class holds common attributes and methods;

- Inheritance enhances reuse of code and reduces maintenance costs;

- Faster development time because existing code (base class) is already tested.

You might also like