青春树丶
2021-12-08 00:03
采纳率: 50%
浏览 38
已结题

Java构造方法问题


public class student{
    private int age;
    private String name;
    private String grade;

    public student(){
        this(99,"李","2020");
    }
    public Student(int age,String name,String grade){
        this.age = age;
        this.name = name;
        this.grade = grade;
    }
    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }
}

编译时候提示:java: 方法声明无效; 需要返回类型
报错是在有参构造那一行。我构造名与类名都一致,怎么还会报错?(初学Java)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题