Java基础入门课后习题第三单元第六题一
class Student{
private String name;
private double sore;
public Student(){//无参构造方法
}
public Student(String name, double sore){//有参构造方法
this.name = name;
this.sore = sore;
}
public String getName(){
return name;
}
public double getSore(){
return sore;
}
public void setName(String name){
this.name = name;
}
public void setSore(double sore){
this.sore = sore;
}
}
public class text {
public static void main(String[] args) {
Student stu1 =new Student();//第一种:用无参构造方法为name何sore赋值
stu1.setName("李明");
stu1.setSore(99.9);
Student stu2 =new Student("张亮", 99.8);//第二种:用有参构造方法为name何sore赋值
}
}