java 构造器

葫芦的运维日志

浏览量 6172 2014/01/02 02:09

public class BasicContainer {

     public static void main(String[] args) {
          Person p1 = new Person();//以无参构造器产生实例
          Person p2 = new Person("mike",22,1);//以有参构造器形式产生实例
     }

}

class Person{
     String name;
     int age,sex;
     public Person() {//无参构造函数
     }
     public Person(String name, int age, int sex) {//有参构造函数
          super();
          this.name = name;
          this.age = age;
          this.sex = sex;
     }
}

 

📝 版权声明

本文作者:王梓 | 原文链接:https://www.bthlt.com/note/100-构造器

出处:葫芦的运维日志 | 转载请注明出处并保留原文链接

打赏

留言板

留言提交后需管理员审核通过才会显示

© 冰糖葫芦甜(bthlt.com) 2025 王梓打赏联系方式陕ICP备17005322号-1