Skip to content

Heperowt/Java-OOP-Polymorphism-Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏅 OOP & Polymorphism Demonstration (Java)

Java

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.

🧠 Core OOP Concepts Implemented

1. Abstraction & Inheritance

  • Designed an abstract base class Player to define common attributes (name, team, energy) and establish a contract with the abstract method doTraining().
  • Created concrete subclasses FootballPlayer and VolleyballPlayer that inherit from Player and expand upon it with their unique attributes (goals, blocks, etc.).

2. Polymorphism

  • The Demo class stores different types of players in a single Player[] array.
  • A single polymorphic loop calls doTraining() on each object, and Java automatically resolves the correct overridden method at runtime.

3. Downcasting & Instance Checking

  • Implemented safe downcasting using the instanceof operator to access subclass-specific methods (e.g., getBlocks(), getPoints()) only when the object is explicitly a VolleyballPlayer.

4. Method Overriding

  • Custom implementations of equals() and toString() methods across the hierarchy, utilizing super calls to maintain the inheritance chain and ensure complete object comparison.

🚀 Execution

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.

About

A Java project demonstrating core Object-Oriented Programming principles including Abstract Classes, Inheritance, Polymorphism, and Downcasting using a Sports Player hierarchy.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages