Reputation: 39
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?
Upvotes: 1
Views: 77
Reputation: 1116
Anagram
is considered a regular method in this case because constructor has its own special syntax
public Anagram(String s1, String s2) {}
so it doesn't declare what type it returns.
Upvotes: 0
Reputation: 8354
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){
Upvotes: 6