This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class B { | |
public B() { | |
System.out.println("called.."); | |
} | |
} | |
class A { | |
B b; | |
public static A ints = null; | |
private A() { | |
} | |
public static A getA() { | |
if (ints == null) { | |
ints = new A(); | |
} | |
return ints; | |
} | |
public B getB() { | |
return b; | |
} | |
public void setB() { | |
this.b = new B(); | |
} | |
} | |
public class Demo { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
A a1 = A.getA(); | |
A a2 = A.getA(); | |
a1.setB(); | |
a2.setB(); | |
System.out.println(a1==a2); | |
System.out.println(a1.getB() == a2.getB()); | |
} | |
} |
Comments
Post a Comment