> For the complete documentation index, see [llms.txt](https://educacion.gitbook.io/programacion/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://educacion.gitbook.io/programacion/ud3-introducion-a-programacion-orientada-a-obxectos/atributos.md).

# Atributos

Os **atributos** son as características individuais que diferencian un obxecto doutro e determinan a súa aparencia, estado ou outras cualidades.

Os atributos gardan en **variables denominadas de instancia**, e cada obxecto particular pode ter valores distintos para estas variables.

As variables de instancia, son **declaradas na clase, pero os seus valores son fixados e cambiados no obxecto.**

## Atributos en Java

Os datos que definen unha clase chámanse **atributos**. Por exemplo, a clase `Coche` pode definirse mediante os atributos: `matrícula`<i class="fa-copy">:copy:</i>, `color`, `marca` e `modelo`<i class="fa-copy">:copy:</i>. E a clase `Persoa`<i class="fa-copy">:copy:</i> disporía dos atributos: `nome`, `idade` e `estatura`<i class="fa-copy">:copy:</i>.

Para declarar os atributos dunha clase temos a seguinte sintaxe:

```java
class NomeClase {
    tipo atributo1;
    tipo atributo2;
}
```

<figure><img src="/files/lHJplSzReJREbtDcyLh0" alt=""><figcaption></figcaption></figure>

Os atributos poden ser de diferentes tipos, como:

* **Tipos Primitivos**: Inclúen tipos como `int`, `double`<i class="fa-copy">:copy:</i>, `char`, `boolean`<i class="fa-copy">:copy:</i>, etc.
* **Referencias a obxectos**: Inclúen clases, vectores, etc.

Por exemplo podemos definir os atributos das clases `Coche` e `Persoa`<i class="fa-copy">:copy:</i>:

```java
class Coche{
    String matricula;
    String color;
    String marca;
    String modelo;
}
```

```java
class Persoa{
    String nome;
    byte idade;
    double estatura;
}
```


---

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

```
GET https://educacion.gitbook.io/programacion/ud3-introducion-a-programacion-orientada-a-obxectos/atributos.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.
