Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Jhaymayleth/unidad2_java/llms.txt

Use this file to discover all available pages before exploring further.

Taller 11 introduces abstract classes — classes that define a partial implementation and force concrete subclasses to fill in the blanks via abstract methods. An abstract class acts as a contract: it may hold shared state and concrete helper methods, but one or more of its methods carry no body and are instead marked abstract, making it the responsibility of every concrete subclass to provide a real implementation. This pattern eliminates duplicated structure across related classes while guaranteeing that key behaviour is always customised per type.

Exercises

Ejercicio 1: Figura Abstracta

Define an abstract FiguraT11 class with an abstract calcularArea() method, then implement it in CirculoT11 (π·r²) and RectanguloT11 (base × altura).

Ejercicio 2: Empleado Abstracto

Model an abstract Empleado class requiring subclasses to implement calcularSalario(), with Gerente using a fixed-salary-plus-bonus formula and Vendedor using a commission-based formula.

Ejercicio 3: Mixed Scenarios

Explore pitfalls and best practices around concrete methods inside abstract classes, demonstrating when subclasses should or must override inherited concrete behaviour.

Key Concepts

ConceptDescription
abstract classA class declared with the abstract keyword. It cannot be instantiated directly and may contain both abstract and concrete members.
abstract methodA method with no body, declared inside an abstract class. Every non-abstract subclass must provide an implementation.
Concrete subclassA class that extends an abstract class and implements all abstract methods, making it safe to instantiate.
Cannot instantiateYou can never call new on an abstract class. Any attempt is a compile-time error.
Template method patternA concrete method in the abstract class that calls an abstract method — the base class defines the algorithm skeleton, and subclasses plug in the variable step.

abstract vs Concrete at a Glance

abstract class FiguraT11 {
    // Concrete method — fully defined, inherited as-is
    public void mostrarArea() {
        System.out.println("El área de " + nombre + " es: " + calcularArea());
    }

    // Abstract method — no body; subclasses MUST implement this
    public abstract double calcularArea();
}
Attempting to instantiate an abstract class directly (e.g., new FiguraT11(...)) will cause a compile error: 'FiguraT11 is abstract; cannot be instantiated'.

Compile & Run

All classes in Taller 11 belong to the Taller11 package. From the project root, compile every file in the package first, then run the desired Main class:
# Compile all Taller 11 sources
javac Taller11/*.java

# Run each exercise
java Taller11.MainEjercicio1T11
java Taller11.MainEjercicio2
java Taller11.MainEjercicio3

Build docs developers (and LLMs) love