K
K
Koshkasobaka2020-02-22 22:19:02
Java
Koshkasobaka, 2020-02-22 22:19:02

Java. How to transfer the creation of all objects from Main to another class?

Goodnight. I did the task of creating the parent class and its heirs, and then oops! the last point of the task: create another class and move the creation of an array there from the Main class. I don't understand how to do it. In main, after all, all method calls with this array .. how can I get it from the new class?

public class Main {

public static void main(String[] args) {

Message[] messages = new Message[6];

sendMessage(messages);
displayMessage(messages);
playAudioSetSizeMessage(messages);
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
koperagen, 2020-02-22
@koperagen

The idea of ​​the task, apparently, is that an array is returned from the method of this new class (Let it be MessageService).
How to get? Create an instance of MessageService in main and then call the desired method. Save the result to a variable, similar to creating a new array in the first line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question