2. 编一个封装良好的JavaBean类(无参和带参构造器,setter和getter),类名:Book;属性:String stuName、double price。(10分)
时间: 2023-05-30 08:06:54 浏览: 114
调用setter及getter方法-java课程 ppt
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;
}
}
阅读全文