1.Object类是所有类的父类

  声明一个类的时候,实际上已经默认继承了Object类 

package property;

public class Hero extends Object{
    String name;
    float hp;
    float armor;
    int moveSpeed;
    
    public void useItem(Item i){
        System.out.println("Hero use item");
        i.effect();
    }
    
    public Hero(){
        System.out.println("Hero的无参构造方法");
    }
    
    public Hero(String name){
        System.out.println("Hero的有参构造方法");
        this.name=name;
    }
    
    public static void main(String[] args){
        new Hero();
    }
}
View Code

相关文章:

  • 2021-08-09
猜你喜欢
  • 2021-08-09
  • 2021-05-18
  • 2022-12-23
  • 2021-11-17
  • 2021-05-14
相关资源
相似解决方案