public class Sentencegenerator {
private String[] subjects;
private String[] verbs;
private String[] directObjects;
public Sentencegenerator(){
subjects = {"Cat", "Dog", "Joe", "Teacher", "Policeman", "Doctor", "Dick"};
verbs = {"eats", "reads", "cums", "farts", "poops", "stabs", "cries"};
directObjects = {"book", "sticker", "fish", "man", "chiwawa", "marker", "cheese"};
}
public Sentencegenerator(String[] mySubjects, String[] myVerbs, String[] myDirectObjects){
subjects = mySubjects;
verbs = myVerbs;
directObjects = myDirectObjects;
}
我知道你只能在初始化数组时创建数组常量,但是有没有办法我可以创建一个数组实例变量,然后创建一个拥有自己常量的构造函数?