This repository demonstrates the concept of inheritance in Java through an employee management system that shows code reduction using Inheritance in JAVA. It includes classes for different types of employees, such as Analysts and Salespersons, showcasing salary raises and bonuses.
In Java, inheritance is achieved using the extends
keyword. Subclasses inherit attributes and methods from their superclass, allowing them to access and utilize common functionalities. This promotes code reuse, as common behaviors can be defined in the superclass and reused across multiple subclasses.
The repository consists of the following Java classes:
Employee
: Base(Super) class representing common attributes and behaviors of employees.Analyst
: Subclass ofEmployee
with additional methods for calculating annual bonuses.SalesPerson
: Subclass ofEmployee
with methods for managing commission percentages.
To use this project:
- Clone the repository:
git clone https://github.com/abhipatel35/java-inheritance-employee-management.git
- Navigate to the cloned directory:
cd java-inheritance-employee-management
- Compile the Java files:
javac *.java
- Run the desired class:
java <ClassName>
public static void main(String[] args) {
Analyst analyst = new Analyst("John", 60000, 30);
System.out.println("Analyst bonus: $" + analyst.calculateAnnualBonus());
}