001package singleton.pub3; 002public abstract class S { 003 private static S newS() { 004 if ("linux".equals(System.getProperty("os.name"))) 005 return new SLinux(); 006 else 007 return new SOther(); 008 } 009 public static final S instance = newS(); 010 public abstract int inc(); 011} 012final class SLinux extends S { 013 private int i; 014 public int inc() {return ++i;} 015} 016final class SOther extends S { 017 private int i; 018 public int inc() {return --i;} 019}