准备工作
创建一个Teacher类,无参构造器由private修饰,有参构造器由public修饰。
package com.zjl.study.反射;
/**
* Created by zjl 2022/6/13
**/
public class Teacher {
private String name;
private int age;
private Teacher() {
System.out.println("无参数构造器被执行~~~~~~~~");
}
public Teacher(String name, int age) {
System.out.println("有参数构造器被执行~~~~~~~~");
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age