> For the complete documentation index, see [llms.txt](https://v-community.gitbook.io/v-by-example/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://v-community.gitbook.io/v-by-example/en/examples/section_3/methods.md).

# Methods

V does not have classes. But one can define methods for types. A method is a function that has a special receiver argument, only a receiver of the specified type can execute this function. The receiver has its own argument list between `fn` and the method name.

```go
struct User {
    name string
    email string
mut:
    age int
}

fn (u User) can_register() bool {
    return u.age > 15
}

fn (u mut User) has_birthday() {
    u.age += 1
}

fn main() {
    mut bob := User {
        name: 'Bob'
        email: 'bob@bob.com'
        age: 15
    }
    alice := User {
        name: 'Alice'
        email: 'alice@alice-mail.com'
        age: 17
    }
    println(bob.can_register())                                             // false
    println('Bob needs to be 16 to register, but he only is ${bob.age}.')   // Bob needs to be 16 to register, but he only is 15.
    println(alice.can_register())                                           // true
    bob.has_birthday()
    println(bob.age)                                                        // 16
}
```

This code above realizes two methods for receivers `u` of type `User`. Note that the method `has_birthday()` has a `mut` receiver, this is needed here since we want to change its data. The convention of V is not to use receiver names like `self`, `this` or similar things but a short, preferably one letter long, name.

## Exercises

1. Create a method for the type `Person` that determines whether a person is underage or not.
2. Create a method that determines whether an `Animal` has fur or not.


---

# 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://v-community.gitbook.io/v-by-example/en/examples/section_3/methods.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.
