博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第4章 类名作为形参和返回值
阅读量:7093 次
发布时间:2019-06-28

本文共 966 字,大约阅读时间需要 3 分钟。

1.1 类名作为方法的形式参数

1.1.1 案例代码十四:

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);}}

1.2 类名作为返回值案例

1.2.1 案例代码十五:

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();}}

转载于:https://blog.51cto.com/13517854/2087547

你可能感兴趣的文章
随笔-半成品
查看>>
我的友情链接
查看>>
SurfaceView 连续渲染 SurfaceHolder Canvas
查看>>
压缩磁盘节约磁盘空间
查看>>
自动化运维工具ansible学习+使用ansible批量推送公钥到远程主机[学习马哥]
查看>>
我的友情链接
查看>>
Geek爱旅行 - 龙猫
查看>>
《NLP汉语自然语言处理原理与实践》结构图
查看>>
cache和buffer之区别
查看>>
路由协议
查看>>
实用土方之妇科男性科
查看>>
初始MyBatis
查看>>
debian下使用dig/nslookup
查看>>
135.003 智能合约后端优化和产品化
查看>>
解释器模式 Interpreter 行为型 设计模式(十九)
查看>>
K-Modes算法[聚类算法]
查看>>
Const #define
查看>>
Protel 99 SE和AD有铜孔及有铜槽做法
查看>>
grep正则表达式
查看>>
linux下dns服务搭建
查看>>