Question
How can a method be called for an object that is stored in an array from the main method? I need to call a setter
How can a method be called for an object that is stored in an array from the main method?
I need to call a setter method to change the price variable on an object.
NOTE: this is a normal array, I cannot use an array list!!!
Here is the declaration for the array list within the main method.
Employee[] employeeList = new Employee[10];
Here is a new object that was created.
Hourly hourly1 = new Hourly(1002, "Kelly", "Hostess", 25.75);
This is how the object was added to the list.
employeeList[1] = hourly1;
JAVA
I would like to call this method which exists in a subclass of the employee class, the employee class does not extend the main class.
public void setHourlyRate(double hourlyRate){ this.hourlyRate = hourlyRate; }
If i try to call the method like this it works fine: hourly1.setHourlyRate();
However if I try to call the method with the array value: employeeList[1].setHourlyRate();
I can then only call methods from the employee class, how could I make this work?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started