public interface ValueInterface { void printValue(); } public class WindowsValue implements ValueInterface { public void printValue() { System.out.println("This is a value for Windows platform."); } } public class LinuxValue implements ValueInterface { public void printValue() { System.out.println("This is a value for Linux platform."); } } public class Main { public static void main(String[] args) { String osName = System.getProperty("os.name"); ValueInterface value; if (osName.startsWith("Windows")) { value = new WindowsValue(); } else { value = new LinuxValue(); } value.printValue(); } }


上一篇:
下一篇:
切换中文