编一个封装良好的JavaBean类(无参和带参构造器,setter和getter),类名:Book;属性:String stuName、double price
时间: 2023-05-30 16:06:59 浏览: 144
类来封装对象的属性和功能
public class Book {
private String stuName;
private double price;
public Book() {
// 无参构造器
}
public Book(String stuName, double price) {
// 带参构造器
this.stuName = stuName;
this.price = price;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
阅读全文