对象

来源:互联网 发布:sql server 关键技术 编辑:程序博客网 时间:2024/05/16 00:38
public class students {
String name;
 char sex;
 int num;
 int Chinese;
 int Enghlish;
 int Math;
 int avg;

public static void main(String[] args) {
students stu1 =new students();//声明并实例化students类对象stu1
students stu2 =new students();//声明并实例化students类对象stu2
students stu3 =new students();//声明并实例化students类对象stu3
students stu4 =new students();//声明并实例化students类对象stu4
stu1.name = "杨";
stu1.sex ='女';
stu1.num = 162507;
stu1.Chinese =100;
stu1. Enghlish=100;
stu1. Math =100;
stu1. avg = 100;
stu2.name = "高";
stu2.sex ='男';
stu2.num = 162507;
stu2.Chinese =100;
stu2. Enghlish=100;
stu2. Math =100;
stu2. avg = 100;
stu3.name = "章";
stu3.sex ='女';
stu3.num= 162507; 
stu3.Chinese =100;
stu3. Enghlish=100;
stu3. Math =100;
stu3. avg = 100;
stu4.name = "邓";
stu4.sex ='女';
stu4.num= 162507;
stu4.Chinese =100;
stu4. Enghlish=100;
stu4. Math =100;
stu4. avg = 100;
System.out.println(" 姓名 "+"   性别"+"     学号   "+"        语文 "+"      英语 "+"      数学 "+"    平均值 ");
System.out.println(""+stu1.name+ "  "+stu1.sex+"   "+stu1.num+"  "+stu1.Chinese+"  "+stu1. Enghlish+"  "+stu1. Math+"  "+stu1. avg);
System.out.println(""+stu2.name+ "  "+stu2.sex+"   "+stu2.num+"  "+stu2.Chinese+"  "+stu2. Enghlish+"  "+stu2. Math+"  "+stu2. avg);
System.out.println(" "+stu3.name+ "    "+stu3.sex+"   "+stu3.num+"  "+stu3.Chinese+"  "+stu3. Enghlish+"  "+stu3. Math+"  "+stu3. avg);
System.out.println(""+stu4.name+ "  "+stu4.sex+"   "+stu4.num+"  "+stu4.Chinese+"  "+stu4. Enghlish+"  "+stu4. Math+"  "+stu4. avg);
}

}



原创粉丝点击