• 8次练习


    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();
    }

    }

  • 相关阅读:
    zookeeper使用和原理探究(一)
    Zookeeper基本原理
    论照顾小孩与项目管理
    perl启动后台进程
    Oracle数据库迁移
    C# 语言Pagerank两种实现
    没文化真可怕--Silverlight 列冻结
    oracle中使用SQL递归语句的例子
    Visual Studio 2010 智能跟踪文件目录
    oracle wm_concat函数的应用(多行合成一行)
  • 原文地址:https://www.cnblogs.com/Archon-Cty/p/7792763.html
Copyright © 2020-2023  润新知