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();

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

Recommended Answers

All 5 Replies

Interfaces can only contain method signatures and constant declarations.

 Employee emp = new Employee();

Is not allowed. What are you trying to accomplish?

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

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.

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.