创建Student类。定义满足以下条件的Student类,并以自己的信息创建对象,对程序进行测试。Student类的属性:姓名、年龄、班级、学校Student类的方法:自我介绍
要求输出结果如下:
自我介绍:你好!我叫**来自兰职院19应用*班 今年*岁
创建Student类。定义满足以下条件的Student类,并以自己的信息创建对象,对程序进行测试。Student类的属性:姓名、年龄、班级、学校Student类的方法:自我介绍
要求输出结果如下:
自我介绍:你好!我叫**来自兰职院19应用*班 今年*岁
创建Student类,设置属性和toString方法:
public class Student {
String stuname;// 姓名
int age;// /年龄
String classname;// 班级
String school;// 学校
public Student(String stuname, int age, String classname, String school) {
super();
this.stuname = stuname;
this.age = age;
this.classname = classname;
this.school = school;
}
@Override
public String toString() {
return "你好,我叫" + stuname + " 来自" + school + " " + classname + " 今年"
+ age + "岁";
}
//测试
public static void main(String[] args) {
Student stu = new Student("张三", 22, "三年二班", "兰职院");
System.out.println(stu.toString());
}
}
效果图: