Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriden Methods

 
Faiz Abdelhafid
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Good day everyone

Assume I have this code:



And I want to override the setTotalSalary in the subclass to do the following:
1- add overtime hours for the Janitor to the salary. (in the Janitor sub class).
2- add a percentage of the sales to the salesman salary.(in the Salesman sub class).

Is it possible guys ?

Thank you.
 
Campbell Ritchie
Marshal
Posts: 53110
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your setAllowance method with the instanceof is hardly good object-orientation. You should have the allowance percentage in the different classes, then call it from the Employee instance.

But, yes, you probably can override your method.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!