I am trying to make a program and am having trouble with the syntax. I'm trying to create an array as a parameter for an object, but I am having trouble with the syntax.
public class Example {
String[] words;
public Example(words) {
this.words = words;
}
}
public class Construction {
Example arrayExample = new Example({"one", "two", "three"});
}
This gives me an error when I try and compile it. Is there a way to do this without first initializing the array outside the object declaration?
String[] wordsandnew String[]{...}must be used to pass argument.public Example(words) {this.words = words;}topublic Example(String[] words) { this.words = words; }and everything should be out of the box. Be aware that you also gave package access towordsattributes of theExampleclass.