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 }

 

相关文章:

  • 2022-12-23
  • 2022-01-09
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
相关资源
相似解决方案