> 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/ud4-elementos-da-programacion-orientada-a-obxectos/uml-linguaxe-de-modelado-unificada/relacions-entre-clases-herdanza.md).

# Relacións entre clases: Herdanza

O diagrama de clases UML permite representar as relacións entre as diferentes clases que compoñen un dominio concreto.

### Herdanza

A herdanza vai a quedar representada da seguinte forma:

{% @mermaid/diagram content="classDiagram
direction TB  %% TB = Top to Bottom (de arriba a abaixo)

```
%% Clase Persoa - Exemplo completo con visibilidade
class Persoa {
    -id: int = 0
    -nome: String
    -idade: int
    #contadorInstancias: static int
    +Persoa(nome: String, idade: int)
    +getNome() String
    +setNome(nome: String) void
    +calcularAnoNacemento() int
    +getContador()$ static int
}

%% Clase Estudante que herda de Persoa
class Estudante {
    -numeroMatricula: String
    -notaMedia: double
    +Estudante(nome: String, idade: int, matricula: String)
    +estudiar() void
    +getMatricula() String
}

%% Relación de herdanza (Persoa arriba, Estudante abaixo)
Persoa <|-- Estudante : Herdanza



```

" %}

{% hint style="warning" %}
Para facilitar unha maior claridade, os métodos que son **herdados e sobrescritos**, incluiranse no UML da clase fillo.

Os métodos que son **unicamente heredados** (definidos na clase pai), no se incluirán no UML da clase fillo
{% endhint %}


---

# 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/ud4-elementos-da-programacion-orientada-a-obxectos/uml-linguaxe-de-modelado-unificada/relacions-entre-clases-herdanza.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.
