标签:private ring personal void 参数 this main 定义 对象
class Person { private int age; private String name; Person() {}; Person(int nianling,String mingzi) { name = mingzi; age = nianling; };//Personal类中的构造函数对类属性 的一个初始化 } class Demo3 { public static void main(String[] args) { Person man = new Person(); man.name="小明"; man.age = 18; Person woman = new Person(23,"大明"); System.out.println(woman.name + " " + woman.age); System.out.println(man.name + " " + man.age); } }
class Persons { int age; String name; Persons () { /* * 调用有参数的另一个构造函数 */ name = "张三"; age = 23; }; Persons(String name,int age) { this(); this.name = name; this.age = age; } } class Demo8 { public static void main(String[] args) { Persons person = new Persons("Tom",26); System.out.println(person.name + " " + person.age);//结果为TOM,26 } }
标签:private ring personal void 参数 this main 定义 对象
原文地址:https://www.cnblogs.com/bgwhite/p/9375502.html