<>实例:定义一个学生类并封装

<>定义完成后快速封装

鼠标右键单击选中cource >> 转到 >> generate getters and setters…

代码如下:
package 继承; public class Student { private String name ; private int age ;
private String college ; private String depart ; public Student (){} public
Student (String name , int age , String college , String depart) {
this.setName(name); this.setAge(age); this.setCollege(college);
this.setDepart(depart); } public void setName(String name){ this.name = name; }
public void setAge(int age) { this.age = age ; } public void setCollege(String
college){ this.college = college ; } public void setDepart(String depart){
this.depart = depart ; } public String getName(){ return this.name ; } public
int getAge(){ return this.age ; } public String getCollege(){ return
this.college ; } public String getDepart(){ return this.depart; } public String
getInfo(){ return "学生信息如下:" + "\n" + "姓名:" + this.getName() + "\n" + "年龄:" +
this.getAge() + "\n" + "学校:" + this.getCollege() + "\n" + "学院:" +
this.getDepart(); } } class test1{ public static void main (String args[]){
Student stu1 = new Student("张三" , 22 , "shu" , "computer science and
techololege") ; System.out.println(stu1.getInfo()); } }

技术
©2019-2020 Toolsou All rights reserved,
一个名叫“讨火车”的小村子 终于把火车讨来了运营商 网站访客手机号码抓取hive压缩&&hdfs合并小文件精准手机号抓取,运营商大数据函数基本定义和使用‘未完待续Spring Boot教程十六:SpringBoot注入类实现多线程基于神经网络的车辆牌照字符识别技术MyBatis 新增数据 成功 返回 自增主键ID值json反斜杠问题接错水管喝了三年软水?软水和软水机究竟有何用