This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Overriden Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Overriden Methods" Watch "Overriden Methods" New topic
Author

Overriden Methods

Faiz Abdelhafid
Ranch Hand

Joined: Nov 21, 2009
Posts: 32

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
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriden Methods
 
Similar Threads
List Vs Set
java:12: cannot find symbol
hashcode()
Polymorphism
Polymorphism example