类名作为方法的形式参数

 1 package com.mydemo;
 2 
 3 public class Student {
 4     public void study() {
 5         System.out.println("好好学习,天天向上");
 6     }
 7 }
 8 
 9 
10 package com.mydemo;
11 
12 public class Teacher {
13     public void test(Student s) {//接收传递过来的Student对象的地址值
14         s.study();                  
15     }
16 }
17 
18 
19 package com.mydemo;
20 
21 //需求: 调用Teacher的test方法
22 
23 //类名作为形式参数:其实这里需要的是该类对象。
24 public class Test {
25     public static void main(String[] args) {
26         Teacher t = new Teacher();
27         Student s = new Student();
28         t.test(s);    //好好学习,天天向上
29     }
30 }

猜你喜欢

转载自www.cnblogs.com/yifengs/p/10700736.html