类名作为形式参数
要的其实是该类的对象
//Student类
package com.itGIrl_04;
public class Student {
public void study() {
System.out.println("good good study,day day up!");
}
}
//Teacher类
package com.itGIrl_04;
public class Teacher {
public void test(Student s) {
s.study();
}
}
//Test类
package com.itGIrl_04;
/*
* 需求:调用Teacher中的test方法
*
* 类型作为形式参数:其实需要的是该类对象
*/
public class Test {
public static void main(String[] args) {
Teacher t = new Teacher();
Student s = new Student();
t.test(s);
}
}
类名作为返回值
返回的其实是该类的对象
package com.itGIrl_04;
public class Student {
public void study() {
System.out.println("good good study,day day up!");
}
}
package com.itGIrl_04;
public class Teacher {
public Student getStudent() {
Student s = new Student();
return s;
}
}
package com.itGIrl_04;
/*
* 需求:调用Teacher中的test方法
*
* 类型作为返回值:返回的是该类对象
*/
public class Test {
public static void main(String[] args) {
Teacher t = new Teacher();
Student s = t.getStudent();
s.study();
}
}