首页 > 解决方案 > Java中接口和类的继承

问题描述

我不明白为什么在下面的代码中“jm(b)”的输出是“m_AA and m_BA”而不是“m_BB”。谢谢你。(仅适用于:我不知道我要写什么,我不知道我要写什么,我不知道我要写什么,我不知道我要写什么,我不知道我要写什么。)

interface I {
 public void m(A a);
 public static void stampa() {
  System.out.println("stampa");
 }
 class IImpl {
  public static void m(B b) {
   System.out.println("m_IB");
  }
 }
}
class A extends I.IImpl implements I {
 public void m(A a) {
  System.out.println("m_AA");
 }
}
class B extends A {
 public void m(A a) {
  super.m(a);
  System.out.println("m_BA");
 }
 public static void m(B b) {
  System.out.println("m_BB");
 }
}
public class Exercise {
 public static void main(String[] args) {
  B b = new B();
  I j = new B();
  j.m(b);
  System.out.println();
 }
}

标签: javainheritanceinterface

解决方案


推荐阅读