Java static and main method questions.

Asked 2 years ago, Updated 2 years ago, 24 views

This is the content of the assignment.

Requirement 4: The constructor of the Market class internally initializes the scanner class and each class array upon creation, and sets the length of the class array to a maximum of 10. At this time, the value of 10 is a value stored in the static variable array_length, and the length of the class array is set through the corresponding variable. In addition, index variables for each of the five product types are declared to be stored as a number roll index for each product.

The creator of the Market class internally initializes the scanner class and each class array upon creation, and --->>>> What does that mean?

And even if I don't create the main method, can I create a class array?

When you create a static variable and create the main method, you get an error saying, "I don't know why but I don't know why. I don't know why.

java

2022-09-22 18:50

1 Answers

Don't you think they want me to do it like the following?

public class Market {
    private MyClass[] arr;
    private Scanner scan;
    public Market() {
        arr = new MyClass[10];//array initialization
        scan = new Scanner (System.in);// initialize Scanner
    }
}

And there is no correlation between the main method and the class array.

Please upload the code where the error occurs.


2022-09-22 18:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.