# Ch 12: Classes

> Study guide to Crafting Interpreters chapter 12. Classes: class declarations, instances with fields, property get and set, methods, this bound via a small…

Updated October 20, 2026.

## Summary {#summary}

Crafting Interpreters chapter 12, Classes: class declarations, instances with fields, property get and set, methods, this bound via a small closure, and initializers with init(). Budget about 7 hours; the book's `chap12_classes` tests check your code.

## Key facts {#key-facts}

- Week 10 of 145 on the cracked.guide path, in [Crafting Interpreters](https://cracked.guide/crafting-interpreters).
- Time budget: about 7 hours.
- Part of the book: jlox (tree-walk interpreter, Java).
- Verified on cracked.guide when the official `chap12_classes` tests pass on GitHub Actions.
- 3 challenges at the end of the chapter.

## Week 10 goals {#objectives}

By the end of week 10 you can:

- Implement class declarations, instances, and property get and set.
- Explain how methods bind `this` through an extra environment.
- Use init() to set up a new instance's fields.

## This week's steps {#steps}

- Read the chapter: Implement in order and test after each step.
- Write the code in your lox repo: Type it into jlox/ (Java) yourself as you read, and get it running.
- Do the challenges (1–3): Challenges 1 (static methods) and 2 (getter methods) are both good.
- Push and let the tests verify it: Your repo runs the book's chap12_classes tests on every push; passing marks this done.

## Why it matters {#why}

Seeing how objects, methods and this are built from closures and maps explains a lot about JavaScript and Python object models.

## How to approach it {#approach}

Implement in order and test after each step. Work through the explanation of how this is bound by an extra environment; draw it.

## Challenges {#challenges}

3 challenges at the end of the chapter.

Challenges 1 (static methods) and 2 (getter methods) are both good. Challenge 3 is a design discussion about encapsulation. Do challenges that change Lox's behavior on a separate git branch. The cracked.guide check runs the official test suite for this chapter, and a challenge that changes semantics (new syntax, different errors) can make tests fail on main.

## Common traps {#traps}

- Returning the wrong value from init() when called directly.
- Forgetting to bind this when a method is accessed but not immediately called.

## Links {#links}

- [Read the chapter: Ch 12: Classes](https://craftinginterpreters.com/classes.html)
- [Official repo: book source, both interpreters, test suite](https://github.com/munificent/craftinginterpreters)
- [Running the official test suite against your own interpreter (repo README)](https://github.com/munificent/craftinginterpreters#testing-your-implementation)
- [Wikipedia: Class (computer programming)](https://en.wikipedia.org/wiki/Class_(computer_programming))

---

Source: https://cracked.guide/guide/ci-12
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
