package com.itheima_10;
public class Student {
public void study() {
System.out.println("好好学习,天天向上");
}
}
package com.itheima_10;
public class Teacher {
public void test(Student s) {//接收传递过来的Student对象的地址值
s.study();
}
}
package com.itheima_10;
//需求: 调用Teacher的test方法
//类名作为形式参数:其实这里需要的是该类对象。
public class Test {
public static void main(String[] args) {
Teacher t = new Teacher();
Student s = new Student();
t.test(s);
}
}
package com.itheima_11;
public class Student {
public void study() {
System.out.println("好好学习,天天向上");
}
}
package com.itheima_11;
public class Teacher {
public Student getStudent() {
Student s = new Student();
return s;//返回的是Student对象的地址值
}
}
package com.itheima_11;
//需求: 通过Teacher得到Student对象,然后调用Student类的方法
//如果方法的返回值是类名:其实返回的是该类的对象
public class Test {
public static void main(String[] args) {
Teacher t = new Teacher();
Student s = t.getStudent();
s.study();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |