练习023
2023-06-09 本文已影响0人
哈迪斯Java
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);
}
}