本站首页    管理页面    写新日志    退出


[Java]Java Tutorial 读书笔记(Trail Two:Learning the Java Language_5_Interfaces and Packages)
liyang 发表于 2005/7/2 0:46:05

Creating Interfaces What is an Interface 接口中除了可以定义方法,还可以定义常量(constant) Interface vs abstract class# An interface cannot implement any methods, whereas an abstract class can.# A class can implement many interfaces but can have only one superclass.# An interface is not part of the class hierarchy. Unrelated classes can implement the same interface. Defining an Interface Interface declaration 500)this.width=500'>Interface body method 默认为 public abstractconstant 默认为 public static finalno more declaration modifier其它的声明限定符不能用于接口中的方法和变量 Implementing an Interface 【By Convention】The implements clause follows the extends clause, if it exists. 对于constant,实现接口的类使用simple name即可,其它类须使用qualified name Note:When a class implements an interface, it is essentially signing a contract. Using an Interface as a Type 只有实现了接口的类的对象可以被复制指派到相应的接口类型 Warning! Interfaces Cannot Grow Note:Try to anticipate all uses for your interface up front and specify it completely from the beginning. 实在不行,只有使用接口的继承了,即对于新方法新功能放在一个继承于原有接口的新接口中,而实现了原有接口的类根据各自的情况判断是否作出相应改变。 Creating and Using Packages 使用Package的好处: # You and other programmers can easily determine that these classes and interfaces are related.# You and other programmers know where to find classes and interfaces that provide graphics-related functions.# The names of your classes wont conflict with class names in other packages, because the package creates a new namespace.# You can allow classes within the package to have unrestricted access to one another yet still restrict access for classes outside the package. Creating a Package 一般编程情况下,如果没有使用package语句,系统会指定一个default package 解决包名冲突问题:【By Convention】Companies use their reversed Internet domain name in their package names, like this: com.company.package. Some companies now choose to drop the first element com. in this example from their package names. Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including the region or the project name after the company name, for example, com.company.region.package. Using Package Members # Refer to the member by its long (qualified) name# Import the package member# Import the members entire package 系统直接引入的包有:    * The java.langpackage    * The current package by default Managing Source and Class Files hierarchical file systems The qualified name of the package member and the path name to the file arrange your source and class directories separately Each directory listed in the class path is a top-level directory in which package directories appear. From the top-level directory, the compiler and the interpreter can construct the rest of the path, based on the package and the class name for the class.

阅读全文(2098) | 回复(-1) | 编辑 | 精华

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

 
«February 2026»
1234567
891011121314
15161718192021
22232425262728

  公告
暂无公告...

  我的分类(专题)
  最近日志

  最新评论

  留言板

  链接

  Blog信息
blog名称:循环递归
日志总数:11
评论数量:6
留言数量:0
访问次数:61847
建立时间:2005年6月18日



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.414 second(s), page refreshed 144812391 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号