Self introduction

Hello everyone!

My name is Luo Zengchuan, I am 20 years old this year, I am very happy and honored to join the big family of CSDN Blog Forum! My current major is computer, I love programming, and I want to be a programmer in the future. I am more interested and prefer to self-study this major. In this forum, I can not only record my mental journey along the way, but also discuss a lot of things with you. You can also meet more people, enrich yourself in many ways, improve yourself, and grow! Thanks!

 

您好!下面是一个示例的Java代码,实现了"人的类(SelfIntroduction)"和一个主类来测试该类的功能: ```java // 人的类(SelfIntroduction) class SelfIntroduction { // 成员变量 private String name; private int age; private String school; private String major; private String hobbies; // 构造方法 public SelfIntroduction(String name, int age, String school, String major, String hobbies) { this.name = name; this.age = age; this.school = school; this.major = major; this.hobbies = hobbies; } // 成员方法 - 增加信息 public void addInfo(String additionalInfo) { this.hobbies += additionalInfo; } // 成员方法 - 删除信息 public void removeInfo() { this.hobbies = ""; } // 成员方法 - 查看信息 public void displayInfo() { System.out.println("姓名:" + this.name); System.out.println("年龄:" + this.age); System.out.println("就读学校:" + this.school); System.out.println("所学专业:" + this.major); System.out.println("兴趣爱好:" + this.hobbies); } } // 主类 public class MainClass { public static void main(String[] args) { // 创建 SelfIntroduction 对象 SelfIntroduction person = new SelfIntroduction("张三", 20, "ABC大学", "计算机科学", "游泳、读书"); // 查看初始信息 person.displayInfo(); // 增加信息 person.addInfo("、编程"); // 查看更新后的信息 person.displayInfo(); // 删除信息 person.removeInfo(); // 查看最新信息 person.displayInfo(); } } ``` 这段代码定义了一个名为`SelfIntroduction`的类,其中包含了姓名、年龄、就读学校、所学专业和兴趣爱好等成员变量。该类还包含了增加信息、删除信息和查看信息的成员方法。 在主类`MainClass`中,我们创建了一个`SelfIntroduction`对象,并使用各个成员方法来测试该类的功能。首先,我们显示初始信息,然后增加信息,再次显示更新后的信息,最后删除信息并显示最新信息。 请注意,这只是一个示例,您可以根据自己的需求自由添加其他字段和方法。希望对您有所帮助!如果您有任何其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值