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 markedDocumentation 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.
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
| Concept | Description |
|---|---|
abstract class | A class declared with the abstract keyword. It cannot be instantiated directly and may contain both abstract and concrete members. |
abstract method | A method with no body, declared inside an abstract class. Every non-abstract subclass must provide an implementation. |
| Concrete subclass | A class that extends an abstract class and implements all abstract methods, making it safe to instantiate. |
| Cannot instantiate | You can never call new on an abstract class. Any attempt is a compile-time error. |
| Template method pattern | A 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
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 theTaller11 package. From the project root, compile every file in the package first, then run the desired Main class: