标签:get 通过 new t nbsp turn str 天天向上 tst teacher
package com.mydemo2;
public class Student {
public void study() {
System.out.println("好好学习,天天向上");
}
}
package com.mydemo2;
public class Teacher {
public Student getStudent() {
Student s = new Student();
return s;//返回的是Student对象的地址值
}
}
package com.mydemo2;
//需求: 通过Teacher得到Student对象,然后调用Student类的方法
//如果方法的返回值是类名:其实返回的是该类的对象
public class Test {
public static void main(String[] args) {
Teacher t = new Teacher();
Student s = t.getStudent();
s.study();
}
}
标签:get 通过 new t nbsp turn str 天天向上 tst teacher
原文地址:https://www.cnblogs.com/yifengs/p/10700763.html