Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago

Question

understand the key issues concerning international assignments

Answered: 1 week ago