摘自: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.
分享到:
相关推荐
abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是由于这两种机制的存在,才赋予了Java强大的面向对象能力。abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性...
Static Nested Class 和 Inner Class的不同。 Static Nested Class是被声明为静态(static) 的内部类,它可以不依赖于外部类实例被实例化。而通 常的内部类需要在外部类实例化后才能实例化。 25、JSP中动态...
java abstract class interface之间的区别介绍 java abstract class interface之间的区别介绍
override abstract virtual interface比较
自己总结了一下java中static、final、abstract和interface的用法
java中abstractclass和Interface.doc
看到的一个讲interface&abstract class 的感觉不错。
abstract class和interface在Java语言中都是用来进行抽象类。但是两者有什么区别呢,接下来小编给大家带来了abstract 和 interface的区别详解,感兴趣的朋友一起学习吧
主要介绍了 Java abstract class 与 interface对比的相关资料,需要的朋友可以参考下
NULL 博文链接:https://fanlei77.iteye.com/blog/1453579
本文是对PHP中abstract与interface之间的区别进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助
abstract 与virtual : 方法重写时都使用 override 关键字,interface中的方法和abstract方法都要求实现
Struct 、Class、Interface、Abstract各个的特性、应用场景等对比
结论:abstract class和Interface是JAVA语言中的两种定义抽象类的方式。Interface将abstract的概念作了更进一步的发挥。你可以想像Interface是“纯粹”的 abstract class,只可以包含抽象方法,也包括一些常量的定义...
Java中interface接口与abstractclass抽象类的区别共2页.pdf.zip
Abstract This document describes the structure of the Application Binary Interface (ABI) for the ARM architecture, and links to the documents that define the base standard for the ABI for the ARM ...
在Java语言中,abstract class和interface 是支持抽象类定义的两种机制。正是由于这两种机制的存在,才赋予了Java强大的面向对象能力。abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性,...