zoukankan      html  css  js  c++  java
  • 10.30

    package joker;
    
    class Single{
        private static Single instance = new Single();
        private Single() {
        }
        public static Single getInstance() {
            return instance;
        }
        public void print() {
            System.out.println("Hello World!");
        }
    }
    class Human {
        static String name;
        private static int count;
        public Human() {
            count++;
            this.name = "nobody-" + count;
            System.out.println("产生了" + count + "个实例!");
        }
        public Human(String name) {
            this.name = name;
        }
        public String getInfo() {
            return "姓名:" + this.name;
        }
    }
    
    public class HumanDemo{
        public static void main(String[] args){
            System.out.println(new Human().getInfo());
            System.out.println(new Human("K").getInfo());
            System.out.println(new Human("Q").getInfo());
            System.out.println(new Human().getInfo());
            new Human();
            new Human();
            new Human();
            new Human();
            Human h1 = new Human("张三");
            Human h2 = new Human("李四");
            Human h3 = new Human("王五");
            System.out.println("修改之前:" + h1.getInfo() + " " + h2.getInfo() + " " + h3.getInfo());
            Human.name = "赵六";
            System.out.println("修改之后:" + h1.getInfo() + " " + h2.getInfo() + " " + h3.getInfo());
            Single a = null;
            a = Single.getInstance();
            a.print();
        }
    }
  • 相关阅读:
    基督山伯爵---大仲马
    数据结构
    11. 标准库浏览 – Part II
    python 标准库
    Python 官方文件
    Python 函数
    学员名片管理系统
    如何进入多级菜单
    Python 文件操作
    Python 字符串 (isdigit, isalnum,isnumeric)转
  • 原文地址:https://www.cnblogs.com/ELF-CH/p/7822762.html
Copyright © 2011-2022 走看看