HelloWorld
HelloWorld

Reputation: 303

How to easily make a large number of polymorphic assignments?

Currently this is how I do my polymorphic assignments, manually, one by one:

Eg:

employees[ 0 ] = new salariedEmployee();
employees[ 1 ] = new salariedEmployee();
employees[ 2 ] = new commissionEmployee();
employees[ 3 ] = new hourlyEmployee();

How do you assign it more efficiently? Let's say you have to make 20 assignments?

Upvotes: 0

Views: 36

Answers (1)

user4910279
user4910279

Reputation:

Try this.

employee[] employees = {
    new salariedEmployee(),
    new salariedEmployee(),
    new commissionEmployee(),
    new hourlyEmployee(),
};

Upvotes: 1

Related Questions