Discuss / Java / 明明是对的,为什么报错呢?

明明是对的,为什么报错呢?

Topic source

CarlisWang

#1 Created at ... [Delete] [Delete and Lock User]

class PrimaryStudent {

    protected int grade;

    public PrimaryStudent(String name,int age,int score,int grade){

        super(name,age,score);

        this.grade = grade;

  }

    public int getGrade(){

        return this.grade;

  }

}

--------------------------------------------------

Main.java:6: error: incompatible types: PrimaryStudent cannot be converted to Student

        Student ps = new PrimaryStudent("小军", 9, 100, 5);

                     ^

Main.java:40: error: constructor Object in class Object cannot be applied to given types;

        super(name,age,score);

        ^

  required: no arguments

  found:    String,int,int

  reason: actual and formal argument lists differ in length

2 errors

error: compilation failed

明明跟评论中的大部分答案写的一样啊,怎么会报错呢?

GNGGIU_

#2 Created at ... [Delete] [Delete and Lock User]

因为你没有继承student


  • 1

Reply