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

<>定义完成后快速封装

鼠标右键单击选中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,
python 读取 xls文件CSS实现loading小动画vue中数据改变 界面不更新问题JavaSwing实现简单连连看小游戏2019PHP面试题(持续更新中)PHP如何在Vue中使用Echarts可视化库Vue SpringBoot 进行Excel下载c语言实现《学生管理系统》Thinkphp在添加、修改、删除数据时,自动更新Cache缓存的方法WEB前端,初识vue.js