有关abstract interface 和interface的问题??

摘自:SCJP Guide和sun doc

网址:http://www.witscale.com/ebook/Browsable/ebook078.htm

网址:http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html


To summarize the modifiers in relation with interfaces, note that

         Interface can be declared with either public or default access . It is implicitly abstract.

         Interface methods are by default public and abstract.

         Interface variables are by default public, static and final.

1.接口可以声明为public(公共)或默认的访问权限。接口隐含表明是抽象的(abstract)的。
2.接口的方法默认即为public(公共)且是abstract(抽象)的.
3.接口中的变量默认即为public(公共), static(静态) and final(最终的)。

Table 3.3 shows the various combinations for the interface methods and constant declarations and how the compiler sees them.


Table 3.3 Valid declarations of interface methods and constants


Interface declarations

How the compiler interprets them

public interface Searchable {}

public abstract interface Searchable {}

abstract interface Searchable {}

abstract interface Searchable {}

interface Searchable {}

abstract interface Searchable {}

void search(String searchString);

public abstract void search(String searchString);

abstract void search(String searchString);

public abstract void search(String searchString);

public void search(String searchString);

public abstract void search(String searchString);

char MATCH_ONLY_ONE = ‘?’;

public static final char MATCH_ONLY_ONE = ‘?’;

public char MATCH_ONLY_ONE = ‘?’;

public static final char MATCH_ONLY_ONE = ‘?’;

static  MATCH_ONLY_ONE = ‘?’;

public static final char MATCH_ONLY_ONE = ‘?’;

final char MATCH_ONLY_ONE = ‘?’;

public static final char MATCH_ONLY_ONE = ‘?’;

final public char MATCH_ONLY_ONE = ‘?’;

public static final char MATCH_ONLY_ONE = ‘?’;




The order of modifiers does not matter in any variable or method declaration. For instance, the declaration public abstract static method(); is same as the abstract public static method(); . It is also the same as abstract static public method(); . By convention, however, the access modifier (if any) is written before the other modifiers.


Interfaces specify the set of methods that have to be implemented ultimately by a concrete (non-abstract class).

Abstract will specify a method which is not implemented in an abstract base class, and that must be implemented in a concrete subclass.


A side note; Values defined in an interface are public static final my default so

int VALUE = 5;

is the same as

public static final int VALUE = 5;

in an interface.


abstract Interfaces

Every interface is implicitly abstract . This modifier is obsolete and should not be used in new programs.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值