创建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());
}
}
效果图:
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
System.out.println("Helloword")