练习023

作者: 哈迪斯Java | 来源:发表于2023-06-09 12:09 被阅读0次

    public class AutoPlant extends Factory {
    String productsName;

    public AutoPlant(String productsName) {
        this.productsName = productsName;
    }
    
    @Override
    public String produce() {
        return this.productsName;
    }
    

    }

    public abstract class Factory {
    String name;

    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public abstract String produce();
    

    }

    public class ShoeFactory extends Factory {
    String productsName;

    public ShoeFactory(String productsName) {
        this.productsName = productsName;
    }
    
    @Override
    public String produce() {
        return this.productsName;
    }
    

    }

    public class Test {
    public static void main(String[] args) {
    AutoPlant autoPlant = new AutoPlant("汽车");
    autoPlant.setName("汽车厂");
    System.out.println(autoPlant.getName() + "生产的是" + autoPlant.productsName);
    ShoeFactory shoeFactory = new ShoeFactory("鞋");
    shoeFactory.setName("鞋厂");
    System.out.println(shoeFactory.getName() + "生产的是" + shoeFactory.productsName);
    }
    }

    相关文章

      网友评论

          本文标题:练习023

          本文链接:https://www.haomeiwen.com/subject/kzphddtx.html