This project serves as a practical demonstration of core Object-Oriented Programming (OOP) principles in Java. It models a sports hierarchy to showcase how different objects can interact under a unified structure using Polymorphism.
- Designed an abstract base class
Playerto define common attributes (name, team, energy) and establish a contract with the abstract methoddoTraining(). - Created concrete subclasses
FootballPlayerandVolleyballPlayerthat inherit fromPlayerand expand upon it with their unique attributes (goals, blocks, etc.).
- The
Democlass stores different types of players in a singlePlayer[]array. - A single polymorphic loop calls
doTraining()on each object, and Java automatically resolves the correct overridden method at runtime.
- Implemented safe downcasting using the
instanceofoperator to access subclass-specific methods (e.g.,getBlocks(),getPoints()) only when the object is explicitly aVolleyballPlayer.
- Custom implementations of
equals()andtoString()methods across the hierarchy, utilizingsupercalls to maintain the inheritance chain and ensure complete object comparison.
The application runs entirely in the console, generating player objects, invoking training routines, and filtering for highly successful athletes based on real-time state changes.