【无标题】

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);
}

}

上一篇:Oracle数据库学习笔记(六)


下一篇:简单介绍一下原型和原型链