标签:override 简单 str new ace string actor sys lang
Shape.java
public interface Shape {
void draw();
}
Circle.java
public class Circle implements Shape{
@Override
public void draw() {
System.out.println("i‘m a circle");
}
}
Rectangle.java
public class Rectangle implements Shape{
@Override
public void draw() {
System.out.println("i‘m a rectangle");
}
}
工厂类ShapeFactory.java
public class ShapeFactory {
public static Shape getShape(String name) {
if ("circle".equals(name)) {
return new Circle();
}
if ("rectangle".equals(name)) {
return new Rectangle();
}
return null;
}
}
标签:override 简单 str new ace string actor sys lang
原文地址:https://www.cnblogs.com/wishee/p/14952181.html