> For the complete documentation index, see [llms.txt](https://docs.budgielang.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.budgielang.org/syntax/classes.md).

# Classes

The concept of creating instances of classes with access to member variables and methods is common across languages.

Create a class with `class start`. It takes in, at the very least, the name of the class (in PascalCase as with functions). You can then also provide `extends` and a name of a class to indicate a single class to inherit from.

End it with `class end`.

```
class start : Word
    comment line : ...
class end

class start : Noun extends Word
    comment line : ...
class end
```

In C#:

```csharp
class Word
{
    // ...
}

class Noun : Word
{
    // ...
}
```

In Python:

```python
class Word:
    # ...

class Noun(Word):
    # ...
```

## Constructors

Constructors, or initialization methods, are called when a new instance of a class is created. It's declared with `constructor start`, which takes the publicity of the constructor, the name of the class, and any number of (name, type) arguments, and `constructor end`.

Inherited classes that define a constructor must provide an additional `base` argument along with any parameters to call to their parent class' constructor.

```
class start : Noun extends Word
    constructor start : public Noun name string base
        print : { concatenate : ("Creating ") name }
    constructor end
class end
```

In C#:

```csharp
class Noun : Word
{
    Noun(string name)
        : base()
    {
        Console.WriteLine("Creating " + name);
    }
}
```

In Python:

```python
class Noun(Word):
    def __init__(self, name):
        super().__init__()
        print("Creating " + name)
```

## This

You can pass a reference to the current class using the `this` command.

```
this
```

* In C#: `this`
* In Python: `self`

## New

Create new instances of classes with the `new` command. It takes in the name of the class and any number of arguments to pass to the parameter.

```
variable : fruit Noun { new : Noun "apple" }
```

* In C#: `Noun fruit = new Noun("apple");`
* In Python: `fruit = Noun("apple")`

## Exports

You can export classes from the current file by including the `export` keyword before the class' name.

```
class start : export Word
    comment line : ...
class end
```

In C#:

```csharp
public class Word
{
    // ...
}
```

In Python:

```python
class Word:
    // ...
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.budgielang.org/syntax/classes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
