I am currently coding an RPG using java classes as a side project after completing my OODP course. I have 3 classes which this problem is concerned with. A Job class, a Knight Class and a Skills Class. Knight inherits the properties from the Job class and has a "has a" relationship with the Skills class. The code snippet of Knight Class is shown below. My issue is that the second last line, skills.add(slash); is getting multiple errors. I tested with just an array list of Integers to add Integers to the array list resulting in the same set of errors. Is there something wrong with my code or syntax here?
import java.util.ArrayList;
public class Knight extends Job {
public Knight() {
super("Knight");
}
private ArrayList<Skills> skills = new ArrayList<Skills>();
Skills slash = new Skills(5, 1, "Slash");
skills.add(slash);
}
This is the constructor for the Skills class
public Skills(int dps, int mana, String name) {
this.dps=dps;
this.mana=mana;
this.name=name;
}
These are the errors I have encountered
Multiple markers at this line
- Syntax error, insert ")" to complete MethodDeclaration
- Syntax error, insert "SimpleName" to complete
QualifiedName
- Syntax error on token ".", @ expected after this token
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
slashwith package private access. I suspect you wanted to putskills.add(new Skills(5,1,"Slash"));in your constructor.private ArrayList<Skills> skills= new ArrayList<Skills>(); Skills slash= new Skills(5,1,"Slash"); skills.add(slash);in a method/initialization block/constructor.