package p1; /** * @author WanJl * @version 1.0 * @title p1.Product * @description 商品类 * @create 2026/7/20 */ public class Product { /** * 品牌 */ private String brand; /** * 名称 */ private String name; /** * 价格 */ private double price; /** * 数量 */ private int count; /** * 为商品品牌赋值 * @param newBrand */ public void setBrand(String brand){ //如果 方法参数 使用的是brand(方法参数也属于局部变量) 和成员变量名相同, // 在当前方法中,按照就近原则,会都使用的是局部变量,而不是使用成员变量 //所以,要么就为局部变量设置新的变量名。 //要么就使用this关键字, 通过this关键字调用的变量是当前对象的成员变量。调用的方法是当前对象的成员方法。 //this主要的作用就是区分同名的成员变量和局部变量。使用this调用的就一定是成员变量 // 我 me 俺 寡人 孤 洒家 this.brand=brand; } /** * 获取商品的品牌 * @return */ public String getBrand(){ return brand; } public void setName(String name){ this.name=name; } public String getName(){ return this.name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } }