2
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;
}

配列を初期化するときにしか配列定数を作成できないことは知っていますが、配列インスタンス変数を作成してから、独自の定数を持つコンストラクターを作成する方法はありますか?

4

1 に答える 1