大概可能是这样
public class Student {
private String name;//姓名
private float chengji;//成绩
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getChengji() {
return chengji;
}
public void setChengji(float chengji) {
this.chengji = chengji;
}
//无参构造函数
public Student(){
this.chengji = 90f;
this.name = "小明";
}
//有参构造函数
public Student( String name1,float chengji1){
this.chengji = chengji1;
this.name = name1;
}
}
你在另外类中
Student s = new Student("小红",100f);
此时s中name为小红,成绩是100
如果Student s = new Student();
s中name为小明 成绩是90