SLIDE 1 / 4

1. The Blueprint and the Buildings: Class vs Objects

A Class is merely the conceptual template written in source code. Objects are the tangible instances living in the Heap at runtime. A single architectural blueprint spawns thousands of autonomous houses.

Plano: CuentaBancaria String numero String titular double saldo depositar(monto) retirar(monto) c1 (@0x1001) Lucía $5.000 c2 (@0x1002) Marcos $120 c3 (@0x1003) Elena $94.000
State Isolation c2.depositar($500);
Cuenta c1 (Lucía): $5.000 (Sin cambios)
Cuenta c2 (Marcos): $120
Cuenta c3 (Elena): $94.000 (Sin cambios)

Each instance encapsulates its own state. Mutating c2 has zero impact on c1 or c3 memory.

2. The 4-Step Lifecycle of new Operator

Persona p = new Persona("Ana", 28); executes in 4 distinct memory phases: Allocation, Zeroing, Constructor invocation, and Pointer assignment.

Stack (main) Persona p null Heap @0x5A10: Persona nombre: null edad: 0 Memoria no reservada
FASE 1 / 4: RESERVA
Active Phase: 1. Reserva de Memoria
Local variable p: null (sin apuntar)
Heap State: Bloque reservado en 0x5A10

The new keyword requests continuous space in the Heap to accommodate Persona fields.

3. The this Pointer and Variable Shadowing

When a method parameter shares an identical identifier with a field ("nombre = nombre"), the local parameter shadows the field. The this keyword explicitly addresses the current receiving instance.

setNombre(String nombre) param nombre = "Pedro" nombre = nombre; ¡Se asigna a sí mismo! Objeto @0x5A10 (this) this.nombre "Sin Nombre"
Syntax Selector
Statement executed: nombre = nombre
Field this.nombre: "Sin Nombre" (Intacto)

Without this, the parameter shadows the field. It copies itself into itself, leaving the instance field untouched.

4. References vs Copies: The Risk of Aliasing

In Java, object variables do NOT hold the object: they hold its memory reference. Writing Persona b = a; creates a second remote control aimed at the exact same Heap address.

Stack p1 = 0x5A10 p2 = 0x5A10 Objeto Único en Heap @0x5A10 nombre: "Juan"
Aliasing Mutation Simulator
p1.getNombre(): "Juan"
p2.getNombre(): "Juan"
Objects in Heap: 1 (¡No se duplicó!)

Modifying the object via p2 immediately affects p1 since both reference the exact same memory block.