普通的Class可以实现多个接口吗? [英] Can a normal Class implement multiple interfaces?

查看:207
本文介绍了普通的Class可以实现多个接口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道接口之间可以有多个继承,例如:

I know that multiple inheritances between Interfaces is possible, e.g.:

public interface C extends A,B {...} //Where A, B and C are Interfaces

但是有可能有一个常规的Class继承来自多个接口,如下所示:

But is it possible to have a regular Class inherit from multiple Interfaces like this:

public class A implements C,D {...} //Where A is a Class and C and D are interfaces


推荐答案

Java类只能扩展一个父类。不允许多重继承( extends )。但是,接口不是类,并且类可以实现多个接口。

A Java class can only extend one parent class. Multiple inheritance (extends) is not allowed. Interfaces are not classes, however, and a class can implement more than one interface.

父接口在逗号分隔列表中声明,在实现关键字后。

The parent interfaces are declared in a comma-separated list, after the implements keyword.

总之,,有可能执行:

public class A implements C,D {...}

这篇关于普通的Class可以实现多个接口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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