0

My issue is creating the interface payable and making it compile properly. I have to modify an example out of the book such that is shows polymorphism using an different interface called Payable.
This is what I have for my interface:

  interface Payable
        {
           //-----------------------------------------------------------------
           //  Creates a staff of employees for a firm and pays them.
           //-----------------------------------------------------------------
                void payday();
              Employee emp = new Employee();
                 emp.pay();
         }

The hierarchy is :
Firm-Staff--StaffMember+---Employee+----Executive+-----Hourly+---Volunteer.``Am I even remotely close to doing this right?Thank you for the help!

4
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by Kathy0410
1

Interfaces can only contain method signatures and constant declarations.
this:

 Employee emp = new Employee();
                 emp.pay();

Is not allowed. What are you trying to accomplish?

0

I just have to modify this program, and create a new intereface (Payable), such that it represents polymorphism.

0

You can only declare function and member variables inside interface as Akill10 have already said.

You can't create object and call constructor from interface.
so first clear your doubts about polymorphism in OOP.

Thank you.

0

I assume you meant methods, java doesn't have functions (bit 'picky', but still)
Kathy, what do you mean: create a new interface Payable? you already have one, now you have to use it. for instance:

Employee (as a class) implements Payable, and is extended by Employee/Executive/.. that's closer to what you're trying to do.

0

Yes, I have that done; where the Employee class extends StaffMemeber implents Payable. But, it when I go to run the program it tells me this:

Exception in thread "main" java.lang.StackOverflowError
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.