如何使用超级超类的方法 [英] how to use the method of a super super class

查看:109
本文介绍了如何使用超级超类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我遇到一种情况:我写了3个类A,B,C,类B扩展了类A,而类C扩展了类B.
类A中有一个方法X(),然后我在类B中重写并再次在类C中重写.
现在声明一个类型为C的变量M.如何调用M.X(),其中X()属于类A.

确实需要帮助:)

我在Java中使用JDK 1.6.0

In java, I have a situation : I wrote 3 classes A, B, C, class B extends class A and class C extends class B.
There is a method X() in class A, then I override in class B and override in class C, again.
Now declare a variable M type C. How could I call M.X() in which X() is belonged to class A.

Really need help :)

I code in java, using JDK 1.6.0

推荐答案

编写代码,我认为您无法做到这一点.您可以将X()声明为抽象,然后让每个子类都实现它.
I don''t think you can do this. You could declare X() as abstract and just let each subclass implement it.


您不能,请参见此处[
You can''t, see here [^] (the competitors...) for a rationale.
:)


这篇关于如何使用超级超类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆