我正在尝试用Java制作一个数组,该数组可以输出数组中的武器,但它会不断在底部显示类ID
package package1;
公共类主要{
public static void main(String[] args) {
Weapon wpMace = new Weapon();
wpMace.Damage = 20;
wpMace.StunChance = 2.5f;
wpMace.WepName = "Mace";
// wpMace.Attack();
Weapon wpGun = new Weapon();
wpGun.Damage = 40;
wpGun.StunChance = 0.2f;
wpGun.WepName = "Gun";
//wpGun.Attack();
//Create new array for weapon called weaponArr
Weapon[] weaponArr = new Weapon[4];
weaponArr[0] = new Weapon();
weaponArr[1] = new Weapon();
weaponArr[0].Damage = 32;
weaponArr[0].WepName = "Charger";
weaponArr[1].Damage = 20;
weaponArr[1].WepName = "Boob";
// weaponArr[1] = wpMace;
System.out.println(weaponArr[0]);
System.out.println("");
System.out.println(weaponArr[1]);
}
}
///这是我单独的武器课
package package1;
公开课武器{
public String WepName;
public int Damage;
public float Weight;
public float StunChance;
void Attack(){
System.out.println("You attack with the " + WepName);
System.out.println("It did " + Damage + " points of damage!");
}
}
在底部,我想放置类似System.out.println(weaponArr [0])。Attack())之类的东西;但这只会引发错误
,但目前没有将.Attack()放在最后,它只是在控制台中显示了这些内容
package1.Weapon@15db9742
package1.Weapon@6d06d69c