Home  >  Q&A  >  body text

java - 如何调用祖父类中被覆盖的方法?

public class one
{
    public void hello()
    {
        System.out.println("one");
    }
}

public class two extends one
{
    @Override
    public void hello()
    {
        System.out.println("two");
    }
}

public class three extends two
{
    @Override
    public void hello()
    {
        //如何调用one中的hello方法
    }
}

怎么在three()中调用one的方法了,突然想到了这个问题,google了以后发现没有好的方法或者说是无法实现,这里应该是不能调用super关键字来实现的,java初学者.

怪我咯怪我咯2765 days ago420

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 15:35:36

    The answer is No

    The implementation of your expectation is very strange, you may want to reconsider the design of your program structure

    A class is an abstraction of a type of affairs with the same characteristics. If your three subclass does not have the characteristics of the two parent class, then it should not be a subclass of the two parent class, but should

    that becomes a subclass of one

    reply
    0
  • Cancelreply