码迷,mamicode.com
首页 > 编程语言 > 详细

Java中什么是匿名对象,空参构造方法输出创建了几个匿名对象,属性声明成static

时间:2017-10-23 20:44:25      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:ring   ati   private   static   code   方法   set   ges   log   

package com.swift;
//使用无参构造方法自动生成对象,序号不断自增
public class Person {
    private static int count; //如果在定义类时,使用的是静态的属性,则得到的结果是不同的。count生命周期长,与类相同
    public int id;
    public String name;
    public int age;
    public String city;
    public Person() {
        super();
        count++;
        this.id=count;
        this.name="NoName"+count;
        this.age=20;
        this.city="蜀国";
        System.out.println("生产了 "+count+" 个实例化对象");//调用空参构造方法时输出
        
    }
    public Person(int id ,String name,int age,String city) {
        this.id=id;
        this.name=name;
        this.age=age;
        this.city=city;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getInfo() {
        return "The Person is id=" + id + ", name=" + name + ", age=" + age + ", city=" + city ;
    }
    
}

技术分享

 

Java中什么是匿名对象,空参构造方法输出创建了几个匿名对象,属性声明成static

标签:ring   ati   private   static   code   方法   set   ges   log   

原文地址:http://www.cnblogs.com/qingyundian/p/7718687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!