接口在Java中有构造函数吗?

编程入门 行业动态 更新时间:2024-10-27 10:21:16
本文介绍了接口在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中有构造函数吗?

本文发布于:2023-10-23 04:21:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   函数   接口   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!