Java的super调用案例: super.getClass()返回的是子类自己
2015-05-28 23:44
471 查看
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
如果你要显示父类, 要使用
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()
相关文章推荐
- 《Spring 2之站立会议3》
- JAVA基础笔记——String
- 设计模式(主要java)
- 《Spring2之站立会议2》
- java基础篇——包
- 《Spring2之站立会议1》
- myeclipse修改背景颜色(主题)
- Struts2的主要学习内容
- Java Web目录
- 轻量级javaEE SSH 05: Hibernate
- 轻量级javaEE SSH 04: struts2
- Java基础——其他对象
- Java并发编程:volatile关键字解析
- 轻量级javaEE SSH 03: Spring
- JavaDome
- JAVA敏捷开发环境搭建
- win7 下配置 java 环境变量
- java 虚拟机与并发处理几个问题简要(二)
- Java Servlet学习笔记(七)Servlet Session跟踪
- java 虚拟机与并发处理几个问题简要(二)