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

<>定义完成后快速封装

鼠标右键单击选中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,
MySQL触发器你所不知道的谷歌浏览器 console.log打印技巧3 4j不是合法的python表达式_3+4j不是合法的Python表达式。VHDL——JK触发器算法设计与分析(回溯)登录模块测试用例java 字符串从后向前_Java String字符串总结【linux】shell:简单的shell脚本练习(超详细)Eclipse使用教程——使用Eclipse创建第一个HelloWorld!2021年——第十二届蓝桥杯大赛软件赛国赛C/C++ 大学 C 组