0

How can I pass a variable of type array as a parameter in an instantiated object

I have this on the Main.java Class:

String [] itemList;

Magazine magazine1 = new Magazine(nMagazine, itemList[], distributionPrice, pvp);

This the Magazine.java Class

public class Magazine extends Publication {

 private int numberMagazine;
 private String[] itemList;


public Magazine(int numberMagazine, String[] itemList, float distributionPrice, float pvp) {
    super(distributionPrice, pvp);
    

    this.numberMagazin = numberMagazin;
    this.itemList = itemList;

}

In the main class when I instantiate the magazine1 object I can't call the itemList[] variable and I don't understand why

1

1 Answer 1

2

You need to remove the braces [] when you reference the array. Instead of itemList[] it should be just itemList like this:

String [] itemList;

Magazine magazine1 = new Magazine(nMagazine, itemList, distributionPrice, pvp);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.