zoukankan      html  css  js  c++  java
  • Java中什么是匿名对象,空参构造方法输出创建了几个匿名对象,属性声明成static

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

  • 相关阅读:
    spring整合Quartz
    Quartz基本使用
    hibernate框架基础描述
    POI技术实现对excel的导出
    CG-CTF CRYPTO部分wp
    CG-CTF web部分wp
    快速排序算法的c++实现
    tornado当用户输入的URL无效时转入设定的页面
    sicily 4699. 简单哈希
    unbutu下Io language的解释器安装
  • 原文地址:https://www.cnblogs.com/qingyundian/p/7718687.html
Copyright © 2011-2022 走看看