ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Declare Interfaces

Declare Interfaces

原创 Linux操作系统 作者:keeking 时间:2009-12-21 21:05:57 0 删除 编辑
When you create an interface, you're defining a contract for what a class can do,
without saying anything about how the class will do it. An interface is a contract.

how the methods and variables defined in the interface are declared. These rules are strict:
       ■ All interface methods are implicitly public and abstract. In other words,
  you do not need to actually type the public or abstract modifiers in the
  method declaration, but the method is still always public and abstract.
       ■ All variables defined in an interface must be public, static, and final—
  in other words, interfaces can declare only constants, not instance variables.
       ■ Interface methods must not be static.
       ■ Because interface methods are abstract, they cannot be marked final,
  strictfp, or native.
       ■ An interface can extend one or more other interfaces.
       ■ An interface cannot extend anything but another interface.
       ■ An interface cannot implement another interface or class.
       ■ An interface must be declared with the keyword interface.
       ■ Interface types can be used polymorphically .

Declaring Interface Constants

You're allowed to put constants in an interface. By doing so, you guarantee that any class implementing the interface will have access to the same constant.

     Because interface constants are defined in an interface,they don't have to be declared as public, static, or final. They must be public, static, and final, but you don't have to actually declare them that way.





来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7899089/viewspace-623241/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Declare Classes
下一篇: Declare Class Members
请登录后发表评论 登录
全部评论

注册时间:2009-07-23

  • 博文量
    194
  • 访问量
    287361