61B-15: Packages, Access Control, Objects
Contents
Packages and JAR Files
创建包
- At the top of every file in the package, put the package name.
- Make sure that the file is stored in a folder with the appropriate folder name. For a package with name ug.joshh.animal, use folder ug/joshh/animal.
要用的时候import
即可
default package
JAR Files
Access Control
Object Methods: Equals and toString( )
toString( )
== vs equals( )
==
compares referencesequals( )
compares values, but pay attention to the type!
|
|
Rules for Equals in Java
- 反身性:
x.equals(x) == true
- 对称性
- 传递性
注意实现equals方法时,不要违背这些性质!