interface

本文详细介绍了Java中接口的定义方式,包括如何声明接口、继承多个父接口的特点,并解释了接口不能扩展抽象类的原因。文中还强调了接口中的方法默认为公共方法,常量默认为公共静态最终类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

http://docs.oracle.com/javase/tutorial/java/IandI/interfaceDef.html

 

An interface declaration consists of modifiers, the keyword interface , the interface name, a comma-separated list of parent interfaces (if any), and the interface body. For example:

 

public interface GroupedInterface extends Interface1, Interface2, Interface3 {

    // constant declarations
    
    // base of natural logarithms
    double E = 2.718282;
 
    // method signatures
    void doSomething (int i, double x);
    int doSomethingElse(String s);
}

 An interface can extend other interfaces, just as a class can extend or subclass another class. However, whereas a class can extend only one other class, an interface can extend any number of interfaces . The interface declaration includes a comma-separated list of all the interfaces that it extends.

 

2.

All methods declared in an interface are implicitly public , so the public modifier can be omitted.

An interface can contain constant declarations in addition to method declarations. All constant values defined in an interface are implicitly public , static , and final . Once again, these modifiers can be omitted.

 

3. interface can not extends abstract class , because interface can not be instantiatd .

interface also can not implements interfaces , bcz interface can not have specific method body .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值