[上]JAVA学习系列模块八第二章163.封装_快速编写javabean快捷键
视频
笔记
编写符合`JavaBean` 规范的类,以学生类为例,标准代码如下:
public class Student { private int sid; private String sname; public Student() { } public Student(int sid, String sname) { this.sid = sid; this.sname = sname; } public int getSid() { return sid; } public void setSid(int sid) { this.sid = sid; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } }
快速生成标准javabean通用快捷键:alt+insert
1. 生成无参构造:
2.生成有参构造
3.生成get/set方法:
public class Test01 { public static void main(String[] args) { Student s1 = new Student(); s1.setSid(1); s1.setSname("涛哥"); System.out.println(s1.getSid()+"..."+s1.getSname()); System.out.println("=============="); Student s2 = new Student(2, "金莲"); System.out.println(s2.getSid()+"..."+s2.getSname()); } }