zoukankan      html  css  js  c++  java
  • Java作业八(2017-10-30)

    public class TAutoPerson {
    	public static void main(String args[]) {
    		          new Person();
    		          new Person();
    		          new Person();
    		          new Person();
    		          new Person();
    		          
    		     }
    		 }
    		     class Person{
    		         private String name;
    		         private static  int count;
    		         public Person() {
    		             count++;
    		             System.out.println("产生了" + count +"个实例化对象。 ");
    		         }
    		         public String getInfo() {
    		             return "姓名: " + this.name;
    		         }
    		     
     }
    

        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());
    		 
    		     }
    		 }
    		     class Person{
    		         private String name;
    		         private static int count;
    		         public Person() {
    		             count++;
    		             this.name = "NONAME - "+ count ;
    		         }
    		         public Person(String name) {
    		             this.name=name;
    		             
    		         }
    		        public String getInfo() {
    		             return "姓名: "+ this.name;
    		             }
    

    public class TAutoPerson {
    	public static void main(String args[]) {
    		          Single s = null;
    		          s = Single.getInstance();
    		          s.print();
    		      }
    		  
    		  }
    		     class Single{
    		         private static Single instance = new Single();
    		         private Single() {
    		             
    		         }
    		         public static Single getInstance() {
    		             return instance;
    		         }
    		         public void print() {
    		             System.out.println("hello world!!!");
    		         }
    }
    

         

    public class TAutoPerson {
    	public static void main(String[] args) {
    		          Persona per1 = new Persona("张三",30);
    		          Persona per2 = new Persona("李四",31);
    		          Persona per3 = new Persona("张五",32);
    		          System.out.println("---------------------信息修改之前-----------------------------");
    		          System.out.println(per1.getInfo());
    		          System.out.println(per1.getInfo());
    		         System.out.println(per1.getInfo());
    		         System.out.println("---------------------信息修改之后-----------------------------");
    		         Persona.city = "B城";
    		         System.out.println(per1.getInfo());
    		         System.out.println(per1.getInfo());
    		         System.out.println(per1.getInfo());
    		     }
    		 
    		 }
    		 class Persona{
    		     private String name;
    		     private int age;
    		     static String city = "A城";
    		     public Persona(String name,int age) {
    		         this.name = name;
    		         this.age = age;
    		     }
    		     public String getInfo() {
    		         return " 姓名:"+ this.name + ",年龄:" + this.age + ", 城市: "+city;
    		     }
    }
    

      

    public class TAutoPerson {
        public static void main(String[] args) {
        	TAutoPerson s=TAutoPerson.getSinglePerson();
                 System.out.println(s.toString());//得到唯一的对象
             }
     
         private String name="The God";
         private int age=10000;
         private static TAutoPerson  person=new TAutoPerson();//生成对象放在java静态池中,否则如果非静态在堆中,生命周期比类短
         private TAutoPerson() {};//构造方法私有化可以避免大量实例化对象而消耗内存
         public static TAutoPerson getSinglePerson() 
             return person;
         }
         @Override
         public String toString() {
             return "SinglePerson [name=" + name + ", age=" + age + "]";
         }
    }
    

      

  • 相关阅读:
    dialogue中需要添加编辑器
    表格增加整行和删除整行
    树形菜单配合element-ui模糊搜索和鼠标单击选择内容变色并且滚动
    格式金钱【摘抄与网络,记录】
    element-ui日期选择器
    普通上传
    axios另类封装
    Android permission 访问权限大全
    Android Timer 的 schedule()方法定时循环切换图片
    Android 设置图片倒影效果
  • 原文地址:https://www.cnblogs.com/chengxuyuanGM/p/7793390.html
Copyright © 2011-2022 走看看