标签:new show static tor str system [] const class
package Test;
/*
* 若没给构造方法时,系统会默认给出空参构造;若给出了构造方法,系统则不在提供一个无参构造
*
*/
public class Constructor {
public static void main(String[] args) {
PersonStu p=new PersonStu();
p.show();
PersonStu p1=new PersonStu("kobe",39);
p1.show();
}
}
class PersonStu {
private String name;
private int age;
//public Person() {} 默认空参构造
public PersonStu() {
System.out.println("空参构造");
}
public PersonStu(String name,int age) {
this.name=name;
this.age=age;
System.out.println("有参构造");
}
public void show() {
System.out.println(name+","+age);
}
}
标签:new show static tor str system [] const class
原文地址:https://www.cnblogs.com/zhujialei123/p/8965104.html