java对象实例化的方式

2021-07-08 02:05

阅读:509

  • */
    public class Book implements Cloneable, Serializable {
    private static final long serialVersionUID = 1L;

    private Integer serialNum; // 序列号
    private String name; // 图书名称

    public Book() {
    System.out.println("默认构造函数");
    }

    public Book(Integer serialNum, String name) {
    System.out.println("带参数构造函数");
    this.serialNum = serialNum;
    this.name = name;
    }

    public int getSerialNum() {
    return serialNum;
    }
    public void setSerialNum(int serialNum) {
    this.serialNum = serialNum;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }

    @Override
    public String toString() {
    if (name == null) {
    return "书籍属性还未填写";
    }

    return serialNum + " : " + name;

    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
    return super.clone();
    }
    }


  • 评论


    亲,登录后才可以留言!