- public class Teacher {
- private int age = 0; // 年龄属性
- private String name = null; // 姓名属性
- private String sex = null; // 性别属性
-
- // 构造函数Teacher完成初始化
- public Teacher(int age,String name,String sex){
-
- this.age = age;
- this.name = name;
- this.sex = sex;
- }
- private void teach(){
-
- System.out.print("[" + name + "]是一位[" + age + "]左右的[" + sex + "]老师,");
- System.out.println("教的课程非常棒,学生们都喜欢听!");
- }
-
- public static void main(String[] args) {
-
- new Teacher(26,"王晓明","女").teach();
- }
- }
复制代码 |