类的静态属性,动态属性
package lol;
public class Hero {
String name; //姓名
float hp; //血量
{hp = 200;}//对象属性初始化
static{
int itemCapacity = 6;//静态初始化块 初始化
}
float armor; //护甲
int moveSpeed; //移动速度
static String copyright;//类属性,静态属性
public Hero(){
System.out.println("实例化一个对象的时候,必然调用构造方法");
}
//类方法,静态方法
//通过类就可以直接调用
public static void battleWin(){
System.out.println("battle win");
}
//回血
public void huixue(int xp){
hp = hp + xp;
//回血完毕后,血瓶=0
xp=0;
}
public Hero(String name, float hp){
this.name = name;
this.hp = hp;
}
public static void main(String[] args) {
}
}

593

被折叠的 条评论
为什么被折叠?



