package cn.ch.w;
public class Person {
private String name;
private static int count;
public Person()
{
count++;
System.out.println("产生了"+count+"xxxx。");
}
public String getInfo()
{
return "姓名:"+this.name;
}
}
package cn.ch.w;
public class StaticDemo {
public static void main(String args[])
{
new Person();
new Person();
new Person();
new Person();
new Person();
}
}
package cn.ch.w;
public class Person {
private String name;
private static int count;
public Person()
{
count++;
this.name="xxxxxxx-"+count;
}
public Person(String name)
{
this.name=name;
}
public String getInfo()
{
return"你是谁?"+this.name;
}
}
package cn.ch.w;
public class StaticDemo {
public static void main(String args[])
{
System.out.println(new Person().getInfo());
System.out.println(new Person("A").getInfo());
System.out.println(new Person("B").getInfo());
System.out.println(new Person().getInfo());
}
}
package cn.ch.w;
public class Single {
private static Single instance=new Single();
private Single()
{
}
public static Single getInstance()
{
return instance;
}
public void print()
{
System.out.println("xxxxxxx!!");
}
}
package cn.ch.w;
public class SingleDemo {
public static void main(String args[])
{
Single s=null;
s = Single.getInstance();
s.print();
}
}