我没有在demo类中覆盖xyz接口的show方法,为什么这样做有效?

时间:2017-09-20 01:32:42

标签: java-8

public class Demo extends xyz implements abc {

    public static void main(String[] args) {

        abc a = new Demo();
        xyz x = new Demo();
        Demo w = new Demo();

        a.show();
        x.show();
        w.show();

    }

}

interface abc {
    void show();

}

class xyz {
    public void show() {

        System.out.println("show of xyz");
    }
}

输出:

  

显示xyz
  显示xyz
  显示xyz

1 个答案:

答案 0 :(得分:2)

正如https://github.com/pydata/pandas-datareader/issues/394也暗示 -

接口中的默认方法和抽象方法与实例方法一样是继承的。当类或接口的超类型提供具有相同签名的多个默认方法时, Java编译器遵循继承规则来解析名称冲突。

implements

实现此类设计的理想方法是将Traceback (most recent call last): File "/opt/pycharm-2017.2.1/helpers/pycharm/_jb_unittest_runner.py", line 35, in <module> main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING) File "/usr/lib/python3.5/unittest/main.py", line 93, in __init__ self.parseArgs(argv) File "/usr/lib/python3.5/unittest/main.py", line 140, in parseArgs self.createTests() File "/usr/lib/python3.5/unittest/main.py", line 147, in createTests self.module) File "/usr/lib/python3.5/unittest/loader.py", line 219, in loadTestsFromNames suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/lib/python3.5/unittest/loader.py", line 219, in <listcomp> suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName module = __import__(module_name) File "/home/danny/PycharmProjects/AskArby/deals/tests.py", line 3, in <module> from deals.models import Retailer File "/home/danny/PycharmProjects/AskArby/deals/models.py", line 5, in <module> class Retailer(models.Model): File "/home/danny/PycharmProjects/AskArby/deals/models.py", line 6, in Retailer name = models.CharField(max_length=200) File "/home/danny/.virtualenvs/AskArby/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1061, in __init__ super(CharField, self).__init__(*args, **kwargs) File "/home/danny/.virtualenvs/AskArby/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 172, in __init__ self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE File "/home/danny/.virtualenvs/AskArby/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__ self._setup(name) File "/home/danny/.virtualenvs/AskArby/lib/python3.5/site-packages/django/conf/__init__.py", line 39, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 移动到父类。