• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overriden Methods

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic