Java学习----对象的构造

时间:2021-07-14 21:38:21
public class Teacher {
private String teacherName;
private String gendar; // 构造方法:初始化属性值,没有返回类型
public Teacher() {
System.out.println("Teacher类的构造方法");
} public void teach() {
System.out.println("备课");
System.out.println("授课");
} public static void main(String[] args) {
Teacher teacher = new Teacher();
teacher.teach();
}
}

输出:

Teacher类的构造方法
备课
授课