正在加载图片...
E.2 Inheritance 9 Java performs default array initialization.Primitive numeric data types are initialized to zero,and arrays of objects are initialized to null. E.1.8 Packages Many of the core classes for Java are gathered into packages.We do not teach you how to create packages,but we do show how to use the different packages that consistute the core Java application programming interface(API). A package is simply a set of related classes.The naming convention for the core Java packages is java.<package name>.<class name>.The standard package for the core API is java.lang.Many of the more commonly used classes belong to this package,including String and Thread.Therefore,the fully qualified names for these classes are java.lang.String and java.lang.Thread.Classes that belong to java.lang are so common that we can refer to them by their class name,omitting the preceding package name.However,there are many other classes that belong to packages other than java.lang,and they do not follow this rule.In these instances,the fully qualified package name must be used. For example,the Vector class belongs to the package java.util(we look at vectors in Section E.2).To use a Vector,therefore,we must use the following syntax java.util.Vector items new java.util.Vector(); This requirement obviously can lead to cumbersome syntax.The less verbose solution is for the program to declare that it is using a class in a certain package by issuing the following statement at the top(before any class definitions.) import java.util.Vector; Now,we could declare the Vector using the easier style: Vector items new Vector(); However,the most common style people use when they are using packages is import java.util.*; This approach allows the program to use any class in the package java.uti1. The JavaSoft web site (http://www.javasoft.com)includes a complete listing of all packages in the core API. E.2 Inheritance Java is considered a pure object-oriented language.A feature of such languages is that they are able to extend the functionality of an existing class.In object- oriented terms,this extension is inheritance.In general,it works as follows. Assume that there exists a class that has almost all the functionality that isE.2 Inheritance 9 Java performs default array initialization. Primitive numeric data types are initialized to zero, and arrays of objects are initialized to null. E.1.8 Packages Many of the core classes for Java are gathered into packages. We do not teach you how to create packages, but we do show how to use the different packages that consistute the core Java application programming interface (API). A package is simply a set of related classes. The naming convention for the core Java packages is java.<package name>.<class name>. The standard package for the core API is java.lang. Many of the more commonly used classes belong to this package, including String and Thread. Therefore, the fully qualified names for these classes are java.lang.String and java.lang.Thread. Classes that belong to java.lang are so common that we can refer to them by their class name, omitting the preceding package name. However, there are many other classes that belong to packages other than java.lang, and they do not follow this rule. In these instances, the fully qualified package name must be used. For example, the Vector class belongs to the package java.util (we look at vectors in Section E.2). To use a Vector, therefore, we must use the following syntax java.util.Vector items = new java.util.Vector(); This requirement obviously can lead to cumbersome syntax. The less verbose solution is for the program to declare that it is using a class in a certain package by issuing the following statement at the top (before any class definitions.) import java.util.Vector; Now, we could declare the Vector using the easier style: Vector items = new Vector(); However, the most common style people use when they are using packages is import java.util.*; This approach allows the program to use any class in the package java.util. The JavaSoft web site (http://www.javasoft.com) includes a complete listing of all packages in the core API. E.2 Inheritance Java is considered a pure object-oriented language. A feature of such languages is that they are able to extend the functionality of an existing class. In object￾oriented terms, this extension is inheritance. In general, it works as follows. Assume that there exists a class that has almost all the functionality that is
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有