class Program {
public static void main
(String[] args
){ System.
out.
printf("zow = %h \n", Zow.
ZOW_SINGLETON_REF.
getZow());
ZowReference refZowTwo = Zow.ZOW_SINGLETON_REF.getZow().dive(Zow.ZOW_SINGLETON_REF);
System.
out.
printf("zow2 = zow.dive(zow); %h ← %h\n", refZowTwo.
getZow(), Zow.
ZOW_SINGLETON_REF.
getZow());
ZowReference refZowThree = Zow.ZOW_SINGLETON_REF;
System.
out.
printf("zowOne == zowTwo : %s\n", Zow.
ZOW_SINGLETON_REF.
getZow() == refZowTwo.
getZow()); System.
out.
printf("zowOne == zowThree : %s\n", Zow.
ZOW_SINGLETON_REF.
getZow() == refZowThree.
getZow()); }
}
class Zow {
private static final Zow zowSingleton = new Zow();
public static final ZowReference ZOW_SINGLETON_REF = new ZowReference(zowSingleton);
public ZowReference dive(ZowReference refZow2) {
System.
out.
printf("zow2 = %h\n", refZow2.
getZow()); refZow2.setZow(new Zow()); // compile error.
System.
out.
printf("zow2 = %h\n", refZow2.
getZow());
return refZow2;
}
}
class ZowReference {
private final Zow zow;
public ZowReference(Zow zow) {
this.zow = zow;
}
public Zow getZow() {
return this.zow;
}
}
CmNsYXNzIFByb2dyYW0gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncyl7CgkJU3lzdGVtLm91dC5wcmludGYoInpvdyA9ICVoIFxuIiwgWm93LlpPV19TSU5HTEVUT05fUkVGLmdldFpvdygpKTsKCgkJWm93UmVmZXJlbmNlIHJlZlpvd1R3byA9IFpvdy5aT1dfU0lOR0xFVE9OX1JFRi5nZXRab3coKS5kaXZlKFpvdy5aT1dfU0lOR0xFVE9OX1JFRik7CgkJU3lzdGVtLm91dC5wcmludGYoInpvdzIgPSB6b3cuZGl2ZSh6b3cpOyAlaCDihpAgJWhcbiIsIHJlZlpvd1R3by5nZXRab3coKSwgWm93LlpPV19TSU5HTEVUT05fUkVGLmdldFpvdygpKTsKCgkJWm93UmVmZXJlbmNlIHJlZlpvd1Rocm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