# Object-Oriented Programming

> Cambridge Assessment International Education (CAIE) Pseudocode Reference Guide
> Applicable Syllabus: **A Level**

Cambridge A Level (9618) OOP: CLASS declarations, constructor NEW, PUBLIC/PRIVATE encapsulation, inheritance with INHERITS, and SUPER dispatch.

---

Classes are defined with `CLASS..ENDCLASS`. Properties and methods default to `PUBLIC` unless marked `PRIVATE`. Constructors use `NEW`. Inheritance uses `INHERITS` and parent methods are chained with `SUPER`.

### Class Definition &amp; Constructor

```pseudocode
// runnable
// Pet class demo
CLASS Pet
   PRIVATE Name : STRING

   PUBLIC PROCEDURE NEW(GivenName : STRING)
      Name &lt;- GivenName
   ENDPROCEDURE
ENDCLASS

// Creating an object
DECLARE MyPet : Pet
MyPet &lt;- NEW Pet(&quot;Buddy&quot;)
```

### Inheritance &amp; SUPER Dispatch

```pseudocode
CLASS Cat INHERITS Pet
   PRIVATE Breed : STRING

   PUBLIC PROCEDURE NEW(GivenName : STRING,
                        GivenBreed : STRING)
      SUPER.NEW(GivenName)
      Breed &lt;- GivenBreed
   ENDPROCEDURE
ENDCLASS

MyCat &lt;- NEW Cat(&quot;Kitty&quot;, &quot;Shorthaired&quot;)
```

### Encapsulation, Methods &amp; Property Access

```pseudocode
// PUBLIC and PRIVATE visibility
PRIVATE Attempts : INTEGER
Attempts &lt;- 3

PUBLIC PROCEDURE SetAttempts(Number : INTEGER)
   Attempts &lt;- Number
ENDPROCEDURE

PRIVATE FUNCTION GetAttempts() RETURNS INTEGER
   RETURN Attempts
ENDFUNCTION

// Calling methods via dot notation
Player.SetAttempts(5)
OUTPUT Player.GetAttempts()
```


---

* Previous Topic: [File Handling](https://csmasters.dev/docs/pseudocode/file-handling.md)
* Next Topic: [Alphabetical Keyword &amp; Symbol Index](https://csmasters.dev/docs/pseudocode/keyword-index.md)
