Product.java
上传用户:hensond
上传日期:2021-12-27
资源大小:817k
文件大小:1k
- package com.company.section1;
- /**
- * @author cbf4Life cbf4life@126.com
- * I'm glad to share my knowledge with you all.
- */
- public class Product implements Cloneable{
- //产品名称
- private String name;
- //是否可以属性变更
- private boolean canChanged = false;
-
- //产生一个新的产品
- public Product(ProductManager manager,String _name){
- //允许建立产品
- if(manager.isCreateProduct()){
- canChanged =true;
- this.name = _name;
- }
- }
-
- public String getName() {
- return name;
- }
- public void setName(String name) {
- if(canChanged){
- this.name = name;
- }
-
- }
-
- //覆写clone方法
- @Override
- public Product clone(){
- Product p =null;
- try {
- p =(Product)super.clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
- return p;
- }
- }