day06-面向对象类的标准代码JavaBean的规范和快捷键
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
package com.inmind.javabean03;
|
||||||
|
|
||||||
|
public class Student {
|
||||||
|
//属性
|
||||||
|
private String name;
|
||||||
|
private int age;
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
//alt+insert:快速生成javaBean对象
|
||||||
|
|
||||||
|
//有参构造方法
|
||||||
|
public Student(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//满参构造方法
|
||||||
|
public Student(int age, String name, int id) {
|
||||||
|
this.age = age;
|
||||||
|
this.name = name;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
//无参构造方法
|
||||||
|
public Student() {
|
||||||
|
}
|
||||||
|
|
||||||
|
//getter和setter方法
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//自定义的行为(成员方法)
|
||||||
|
public void study(String book){
|
||||||
|
System.out.println("姓名为"+this.name+"的"+this.age+"岁的学生正在学习"+book);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user