java - 扩展类时遇到问题(不明白出了什么问题,也不明白该网站上的其他复杂解释。)

标签 java

基本上,行 super(int health, intstrength, int speed, int type); 一直给我一个错误,说...

.class expected.

这是代码:

public class Pokemon {
    private int health;
    private int strength;
    private int speed;
    private int type;

    public Pokemon(int health, int strength, int speed, int type) {
      assert health >= 0;
      assert health <= 300;
      assert strength >= 1;
      assert strength <= 3;
      assert speed >= 1;
      assert speed <= 300;
      assert type >= 1;
      assert type <= 3;

      this.health = health;
      this.strength = strength;
      this.speed = speed;
      this.type = type; 
    }
}

public class PokemonTester extends Pokemon {
    PokemonTester() {
       super(int health, int strength, int speed, int type);
    }
    {
       Pokemon charizard = new Pokemon(100,2,50,1);
       Pokemon blastoise = new Pokemon(150,2,150,1);
       Pokemon venusaur = new Pokemon(300,2,100,1);
    }
}

最佳答案

删除参数类型并将参数添加到类构造函数中。

PokemonTester(int health, int strength, int speed, int type) {
   super(health, strength, speed, type);
}

关于java - 扩展类时遇到问题(不明白出了什么问题,也不明白该网站上的其他复杂解释。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35964178/

相关文章:

java - 查找文件中每个单词的频率

java - 向 Luke 添加自定义分析器

java - 如何确保 @ExceptionHandler(Exception.class) 在 Spring Boot 中最后被调用?

java - 如何在java中访问列表中的特定元素

java - 为什么不成功 “HTTP GET request with socket ” ?

java - 创建历史事件

c# - 如何对使用线程的方法进行单元测试?

java - 在 JSON 数组中查找 JSON 对象

java - Scala 相当于 Java 的 static block 吗? (没有伴生对象)

java - 登录成功后重定向到原始页面返回原始数据而不是 URL 名称