源码
//成员变量
String name; //名字
double chinese;//语文
double math;//数学
//成员方法 对象的行为
public void printTotalscor(){
System.out.println(name+"的总成绩"+(chinese+math));
}
public void printAhinese() {
System.out.println(name+"的平均成绩"+(chinese+math)/2.0);
}
}
public static void main(String[] args) {
student s1=new student(); //创建对象
s1.name="买买提";//给name赋值
s1.chinese=100;
s1.math=100;
s1.printTotalscor();
s1.printAhinese();
System.out.println("=============");
student s2=new student();
s2.name="";
s2.chinese=90;
s2.math=95;
s2.printTotalscor();
s2.printAhinese();
}
注意实行
- 创建对象 例如 文件名 赋值名 =new 文件名 Student s=new Student
- 我们使用对象的时候 s1点你使用的成员变量名 s1点成员方法
结果图