Search code examples
javamethodsconstructorstringbuffer

Constructor is not working, doesn't accept arguments later when called?


So for an assignment I'm doing (still beginner) I have a default constructor for a class called Anagram and it looks like this:

private StringBuffer word1, word2

public void Anagram(String s, String d){

    StringBuffer word1 = new StringBuffer(s);
    StringBuffer word2 = new StringBuffer(d);
}

But when I call this method from another file,like so:

public Opponent(){
    Anagram an = new Anagram(RandomWord.nextWord(),RandomWord.nextWord());
    turn = 0;
}

I get an error saying the constructor does not accept any arguments? What am I doing wrong?


Solution

  • public void Anagram(String s, String d){ is not a constructor ,constructors don't have return types change it to public Anagram(String s, String d){