Java题!
发布网友
发布时间:2022-05-01 18:24
我来回答
共2个回答
热心网友
时间:2022-06-21 04:00
输出信息重写了toString,输出C语言成绩直接用了变量。可以根据自己需要修改,望采纳
public class Student{
String name;
int age;
String sex;
int grade;
int $class;
double cMark;
public Student(String name, int age, int grade, int $class, double cMark){
this.name = name;
this.age = age;
this.grade = grade;
this.$class = $class;
this.cMark = cMark;
}
public String toString(){
return "姓名: "+name+" 性别: "+sex+" 年龄: "+age+" 年级: "+grade+" 班级: "+$class;
}
}
public class StudentTest{
public static void main(String[] args){
Student stu = new Student("张三",18,3,32,99.5);
System.out.println(stu.toString());
System.out.println(stu.cMark);
}
}
热心网友
时间:2022-06-21 04:01
建Student类对象,并初始化为自己的个人