博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java的super调用案例: super.getClass()返回的是子类自己
阅读量:6941 次
发布时间:2019-06-27

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

If you override a method from your superclass (or your superclass's superclass etc.), super.theMethod() will invoke the original method instead of the one you overrode it with. If you did not actual override theMethod, super.theMethod() will act exactly like theMethod().

In this case I assume you did not override getClass() (in fact I know you didn't because it's final), so super.getClass() acts exactly like getClass(), i.e. either way the getClass method of the Object class is called.

It is, when you call getClass, you're calling the method getClass defined in Object. Object is a superclass of your class (even if not the direct superclass), so you are calling the superclass's version of the method. In fact the superclass's version is the only version of that method

 

如果你要显示父类, 要使用

this.getClass().getSuperclass()

 

转载地址:http://vsgjl.baihongyu.com/

你可能感兴趣的文章
JavaWeb-过滤器Filter学习(一)Filter知识点
查看>>
SSH概念及常用操作汇总
查看>>
Eclipse新版 syso无法自动补全的解决方法
查看>>
Sublime Es6教程1-环境搭建
查看>>
Nginx配置upstream实现负载均衡
查看>>
FFMPEG-AVFilter研究
查看>>
学习笔记DL004:标量、向量、矩阵、张量,矩阵、向量相乘,单位矩阵、逆矩阵...
查看>>
MapReduce(一)
查看>>
有感"全球癌症热点图:患癌负担转至发展中国家"
查看>>
git学习------>从SVN迁移到Git之后,项目开发代码继续在SVN提交,如何同步迁移之后继续在SVN提交的代码到Git?...
查看>>
Kafka——使用java api进行pub & sub
查看>>
Android——Layout:RelativeLayout
查看>>
我的Java开发学习之旅------>Java使用Fork/Join框架来并行执行任务
查看>>
中国大数据争夺战已进入前所未有的高度
查看>>
王志海:充分重视是企业DLP成功的关键
查看>>
Vitalik Buterin:我们正处于 ICO 泡沫,很多人会亏钱
查看>>
湘雅医院黄伟红教授:希望AI专家多来医院讲课,把大数据思维渗到各个医疗环节...
查看>>
戴尔调查:企业忽视新威胁将导致损失
查看>>
WCF技术剖析之十一:异步操作在WCF中的应用(下篇)
查看>>
屏蔽Android PIE检测机制
查看>>