创建和使用对象
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 Teacher(int tage){
}
public void test(String name,int age){
}
public void test(int age,String name){
}
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);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)