首页 > 代码库 > 类的连贯操作

类的连贯操作

package com.model;public class TestClass {        private String name1;    private String name2;    private String name3;        public String getName1() {        return name1;    }    public TestClass setName1(String name1) {        this.name1 = name1;        return this;    }    public String getName2() {        return name2;    }    public TestClass setName2(String name2) {        this.name2 = name2;        return this;    }    public String getName3() {        return name3;    }    public TestClass setName3(String name3) {        this.name3 = name3;        return this;    }}

 

package com.model;public class Main {    public static void main(String[] args) {        TestClass tc = new TestClass();        tc.setName1("张三").setName2("李四").setName3("王二麻子");        System.out.println(tc.getName1());        System.out.println(tc.getName2());        System.out.println(tc.getName3());    }}

技术分享

 

类的连贯操作