Java annotations provide metadata about the code and help in various scenarios like overriding methods, suppressing warnings, and more. This practice focuses on understanding how Java annotations work.
Create a hierarchy of objects with three classes: Worker, OnlineWorker, and OnSiteWorker.
- The
Workerclass should have attributesname,surname,hourlyRate, and a methodcalculateSalary()that takes the number of hours worked as a parameter and returns the salary. - The subclasses should override
calculateSalary(), using the@Overrideannotation. - In the
main()method of thePrincipalclass, make the necessary calls to demonstrate the functionality of@Override.
- Their
calculateSalary()method will take the number of hours worked per month as a parameter. - Salary calculation:
(hoursWorked * hourlyRate) + gasolineBonus. gasolineBonusshould be astaticattribute in this class.
- Their
calculateSalary()method will also take the number of hours worked per month as a parameter. - Salary calculation:
(hoursWorked * hourlyRate) + internetFlatRate. internetFlatRateshould be a constant inOnlineWorker.
- Add some deprecated methods to the subclasses and use the
@Deprecatedannotation. - From an external class, invoke these deprecated methods while suppressing warnings using the appropriate annotation.
- Learn how Java annotations work.
- Understand the use of
@Overridein method overriding. - Apply
@Deprecatedto mark outdated methods. - Use annotations to suppress warnings when needed.
-
Java Version: Jbr17
-
IDE: IntelliJ IDEA (Recommended, but any IDE can be used)
-
Can also be run from the console using appropriate commands
- Repository: π GitHub - S107Annotations
Happy coding! π