Java的super调用案例: super.getClass()返回的是子类自己

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

 

posted on 2015-05-28 23:44  Milton  阅读(356)  评论(0编辑  收藏  举报

导航