首先
避免使用该名称Character
,因为java.lang
包中有一个已命名的类Character
,它是原始数据类型的包装类char
。
该类java.lang.Character
用于自动装箱转换,更多信息在这里
其次
将该类重命名为Champion
,它肯定会起作用。:)
第三
,您没有将正确的参数传递给参数。当您将括号留空时,您的构造函数需要参数
它看起来像什么
public class Character {//<-- avoid this name
public int attack, rangedAttack, manaAttack, defense, rangedDefense, manaDefense, strength, agility, intelligence ,race;
String name;
public Character(String Name, int Race) {
name = Name;
race = Race;
};//<-- Y U PUT SEMICOLON ?
public class QuestOfVallock{
public static void main(String[] args){
Character self = new Character(); //<-- Y U NO GIVE HIM PARAMETERS ?
}
它应该是什么
public class Champion { //<-- Java-approved name
public int attack, rangedAttack, manaAttack, defense, rangedDefense, manaDefense, strength, agility, intelligence ,race;
String name;
public Character(String Name, int Race) {
name = Name;
race = Race;
}//<-- No semicolon
}//<-- Closing brace for class
public class QuestOfVallock{
public static void main(String[] args){
Champion self = new Champion("Little Java Child",1001); //<-- Unique race
}
}//<-- closing brace for class
我还建议
Race
在
interface
public interface RaceConstants {
int ELF = 1;
int JAVA_CHILD = 1001;
int DWARF = 2;
}
所以你main()
看起来像这样:
public static void main(String[] args){
Champion self = new Champion("Little Java Child",RaceConstants.JAVA_CHILD; //<-- Unique race
}