public class Teacher {
//属性:成员变量
String name;
int age;
//定义一个空构造方法
public Teacher(){
System.out.println("空构造方法被调用了......");
}
//定义一个有参构造方法
public Teacher(String tname,int tage){
System.out.println("Teacher(String name,int age)构造方法被调用了......");
name = tname;
age = tage;
}
public Teacher(int tage,String tname){
}
public void show(){
}
public void show(String name,int age){
}
public void show(int age){
}
public static void main(String[] args) {
//创建对象
Teacher teacher1 = new Teacher();
teacher1.name = "张飞";
teacher1.age = 18;
System.out.println(teacher1.name);
System.out.println(teacher1.age);
Teacher teacher2 = new Teacher("关羽",20);
System.out.println(teacher2.name);
System.out.println(teacher2.age);
}
}