学生类Student
属性:语文成绩chinese,数学成绩math,英语成绩english
行为:求总成绩的方法getSum()
class Studnt {
public static void main(String[] args) {
Studentl p =new Studentl();
p.setChinese(88);
p.setMath(98);
p.setEnglish(78);
System.out.println(p.getChinese()+" "+p.getMath()+" "+p.getEnglish()+" "+p.getSum() );
}
}
class Studentl{
private int chinese;
private int math;
private int english;
public void setChinese(int chinese){
this.chinese =chinese;
}
public int getChinese(){
return chinese;
}
public void setMath(int math)
{
this.math =math;
}
public int getMath()
{
return math;
}
public void setEnglish(int english)
{
this.english =english;
}
public int getEnglish()
{
return english;
}
public int getSum(){
return chinese+math+english;
}
}
|
|