import java.util.Random;
public class PouAbilites {
protected int Health;
public int getHealth(){
return this.Health;
}
public void setHealth(final int Health){
final Random random = new Random();
final int randomInt = random.nextInt(100)+1;
this.Health=randomInt;
}
PouAbilites(){
this.Eletero=getEletero();
}
public void onscreen(){
System.out.println("Health: "+ this.Health);
}
}
main
函数包含在另一个类中:
package KotelezoProgram;
public class Main {
public static void main(final String[] args) {
final PouAbilites Pou = new PouAbilites();
Pou.onscreen();
}
}
答案 0 :(得分:0)
在
之间调用setHealth()
PouAbilites Pou = new PouAbilites();
Pou.onscreen();
呼叫
在onscreen()
之前调用setHealth()
将返回0
,因为this.Health
刚刚在Pou
对象中初始化为零。