接口在Java中有构造函数吗? [英] Do interfaces have a constructor in Java?

查看:560
本文介绍了接口在Java中有构造函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Java中的接口由虚拟机作为抽象类处理。因此,Java中的每个类,抽象与否都有一个构造函数。这是否意味着接口也有构造函数?因为一方面我也有理由拥有一个构造函数,因为它们是抽象类。另一方面,它没有意义,因为接口没有任何初始化属性。
那么它实际上是如何工作的?

I know that interfaces in Java are handled by the virtual machine as abstract classes. So, every class in Java, abstract or not has a constructor. Does this mean that interfaces have a constructor too? Because too me on one hand makes sense to have a constructor since they are abstract classes. On the other hand it doesn´t make sense since interfaces don´t have any attributes to initialize. So how does it actually work?

推荐答案

接口没有构造函数。他们的实现做。

Interfaces don't have constructors. Their implementations do.

这篇关于接口在Java中有构造函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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