# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
