[转帖]变态级JAVA程序员面试32答
<p><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;"><font color="#000000" size="5"><a href="http://www.hzguigu.com/bbs">www.hzguigu.com/bbs</a></font></span></p><p><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第一,谈谈</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">final, finally, finalize</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的区别。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>final—</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">修饰符(关键字)如果一个类被声明为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">final</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> abstract</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的,又被声明为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">final</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的。将变量或方法声明为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">final</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">,可以保证它们在使用中不被改变。被声明为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">final</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。被声明为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">final</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的方法也同样只能使用,不能重载</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>finally—</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">再异常处理时提供</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> finally </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">块来执行任何清除操作。如果抛出一个异常,那么相匹配的</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> catch </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">子句就会执行,然后控制就会进入</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> finally </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">块(如果有的话)。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>finalize—</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">方法名。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Java </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">技术允许使用</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> finalize() </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> Object </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">类中定义的,因此所有的类都继承了它。子类覆盖</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> finalize() </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">方法以整理系统资源或者执行其他清理工作。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">finalize() </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">方法是在垃圾收集器删除对象之前对这个对象调用的。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第二,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Anonymous Inner Class (</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">匿名内部类</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">) </span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">是否可以</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">extends(</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">继承</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">)</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">其它类,是否可以</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">implements(</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">实现</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">)interface(</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">接口</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">)?</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">匿名的内部类是没有名字的内部类。不能</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">extends(</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">继承</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">) </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">其它类,但一个内部类可以作为一个接口,由另一个内部类实现。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第三,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Static Nested Class </span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">和</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> Inner Class</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的不同,说得越多越好</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">(</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">面试题有的很笼统</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">)</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Nested Class </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">(一般是</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">C++</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的说法),</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Inner Class (</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">一般是</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">JAVA</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的说法</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">)</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Java</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">内部类与</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">C++</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">嵌套类最大的不同就在于是否有指向外部的引用上。具体可见</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">http: //www.frontfree.net/articles/services/view.asp?id=704&page=1<br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">注:</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">静态内部类(</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Inner Class</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">)意味着</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">1</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">创建一个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">static</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">内部类的对象,不需要一个外部类对象,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">2</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">不能从一个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">static</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">内部类的一个对象访问一个外部类对象</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第四,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">&</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">和</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">&&</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的区别。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>&</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">是位运算符。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">&&</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">是布尔逻辑运算符。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第五,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">HashMap</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">和</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Hashtable</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的区别。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">都属于</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Map</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">接口的类,实现了将惟一键映射到特定的值上。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>HashMap </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">类没有分类或者排序。它允许一个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> null </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">键和多个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> null </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">值。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
<br/>Hashtable </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">类似于</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> HashMap</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">,但是不允许</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> null </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">键和</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> null </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">值。它也比</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> HashMap </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">慢,因为它是同步的。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第六,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Collection </span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">和</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> Collections</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的区别。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>Collections</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">是个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">java.util</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">下的类,它包含有各种有关集合操作的静态方法。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>Collection</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">是个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">java.util</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">下的接口,它是各种集合结构的父接口。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第七,什么时候用</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">assert</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">断言是一个包含布尔表达式的语句,在执行这个语句时假定该表达式为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> true</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">。如果表达式计算为</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> false</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">,那么系统会报告一个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> AssertionError</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">。它用于调试目的:</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
<br/> assert(a > 0); // throws an AssertionError if a <= 0 <br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">断言可以有两种形式:</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> <br/> assert Expression1 ; <br/> assert Expression1 : Expression2 ; <br/>Expression1 </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">应该总是产生一个布尔值。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
<br/>Expression2 </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">可以是得出一个值的任意表达式。这个值用于生成显示更多调试信息的</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> String </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">消息。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">断言在默认情况下是禁用的。要在编译时启用断言,需要使用</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> source 1.4 </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">标记:</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> <br/> javac -source 1.4 Test.java<br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">要在运行时启用断言,可使用</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> -enableassertions </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">或者</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> -ea </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">标记。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
<br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">要在运行时选择禁用断言,可使用</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> -da </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">或者</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> -disableassertions </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">标记。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
<br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">要系统类中启用断言,可使用</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> -esa </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">或者</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> -dsa </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">标记。还可以在包的基础上启用或者禁用断言。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
<br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">可以在预计正常情况下不会到达的任何位置上放置断言。断言可以用于验证传递给私有方法的参数。不过,断言不应该用于验证传递给公有方法的参数,因为不管是否启用了断言,公有方法都必须检查其参数。不过,既可以在公有方法中,也可以在非公有方法中利用断言测试后置条件。另外,断言不应该以任何方式改变程序的状态。</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"> <br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第八,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">GC</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">是什么</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">? </span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">为什么要有</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">GC? (</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">基础</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">)</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>GC</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">是垃圾收集器。</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Java </span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">程序员不用担心内存管理,因为垃圾收集器会自动进行管理。要请求垃圾收集,可以调用下面的方法之一:</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">
<br/> System.gc()<br/> Runtime.getRuntime().gc()</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第九,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">String s = new String("xyz");</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">创建了几个</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">String Object?</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">两个对象,一个是</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">“xyx”,</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">一个是指向</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">“xyx”</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">的引用对象</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">s</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/></span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">第十,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Math.round(11.5)</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">等於多少</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">? Math.round(-11.5)</span><span style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">等於多少</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: sienna; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">?</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br/>Math.round(11.5)</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">返回(</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">long</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">)</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">12</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">,</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">Math.round(-11.5)</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">返回(</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">long</span><span style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: 宋体; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">)</span><span lang="EN-US" style="FONT-SIZE: 10.5pt; COLOR: #333333; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;">-11;</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体;"><br style="mso-special-character: line-break;"/><br style="mso-special-character: line-break;"/></span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? short s1 = 1; s1 += 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有错,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1+1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">int</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能显式转化为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型。可修改为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1 =(short)(s1 + 1) </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short s1 = 1; s1 += 1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正确。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十二,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">sleep() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;"> wait() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">搞线程的最爱</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法是使线程停止一段时间的方法。在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">时间间隔期满后,线程不一定立即恢复执行。这是因为在那个时刻,其它线程可能正在运行而且没有被调度为放弃执行,除非</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(a)“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">醒来</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的线程具有更高的优先级</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(b)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正在运行的线程因为其它原因而阻塞。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是线程交互时,如果线程对一个同步对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">x </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">发出一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十三,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Java</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">goto?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Goto—java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中的保留字,现在没有在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中使用。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十四,数组有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? String</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">数组没有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法,有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的属性。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>String</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十五,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overload</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Override</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的区别。</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是否可以改变返回值的类型</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法的重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">多态性的不同表现。重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是父类与子类之间多态性的一种表现,重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> (Overriding)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">屏蔽</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(Overloading)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是可以改变返回值的类型。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十六,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Set</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用什么方法来区分重复与否呢</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是用</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">==</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">还是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">equals()? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">它们有何区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">iterator()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法来区分重复与否。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是判读两个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否相等。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">==</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法决定引用值是否指向同一对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十七,给我一个你最常见到的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">runtime exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, <br/>ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十八,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">error</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>error </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出。不可能指望程序能处理这样的情况。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>exception </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十九,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">List, Set, Map</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否继承自</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Collection</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">List</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,Map</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不是</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">interface</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">声明方法的存在而不去实现它的类被叫做抽象类(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">interface</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static final</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">instanceof </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">运算符可以用来决定某对象的类是否实现了接口。</span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? short s1 = 1; s1 += 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有错,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1+1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">int</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能显式转化为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型。可修改为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1 =(short)(s1 + 1) </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short s1 = 1; s1 += 1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正确。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十二,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">sleep() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;"> wait() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">搞线程的最爱</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法是使线程停止一段时间的方法。在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">时间间隔期满后,线程不一定立即恢复执行。这是因为在那个时刻,其它线程可能正在运行而且没有被调度为放弃执行,除非</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(a)“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">醒来</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的线程具有更高的优先级</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(b)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正在运行的线程因为其它原因而阻塞。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是线程交互时,如果线程对一个同步对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">x </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">发出一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十三,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Java</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">goto?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Goto—java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中的保留字,现在没有在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中使用。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十四,数组有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? String</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">数组没有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法,有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的属性。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>String</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十五,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overload</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Override</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的区别。</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是否可以改变返回值的类型</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法的重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">多态性的不同表现。重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是父类与子类之间多态性的一种表现,重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> (Overriding)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">屏蔽</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(Overloading)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是可以改变返回值的类型。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十六,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Set</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用什么方法来区分重复与否呢</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是用</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">==</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">还是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">equals()? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">它们有何区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">iterator()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法来区分重复与否。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是判读两个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否相等。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">==</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法决定引用值是否指向同一对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十七,给我一个你最常见到的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">runtime exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, <br/>ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十八,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">error</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>error </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出。不可能指望程序能处理这样的情况。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>exception </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十九,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">List, Set, Map</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否继承自</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Collection</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">List</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,Map</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不是</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">interface</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">声明方法的存在而不去实现它的类被叫做抽象类(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">interface</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static final</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">instanceof </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">运算符可以用来决定某对象的类是否实现了接口。</span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? short s1 = 1; s1 += 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有错,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1+1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">int</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能显式转化为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型。可修改为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1 =(short)(s1 + 1) </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short s1 = 1; s1 += 1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正确。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十二,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">sleep() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;"> wait() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">搞线程的最爱</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法是使线程停止一段时间的方法。在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">时间间隔期满后,线程不一定立即恢复执行。这是因为在那个时刻,其它线程可能正在运行而且没有被调度为放弃执行,除非</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(a)“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">醒来</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的线程具有更高的优先级</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(b)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正在运行的线程因为其它原因而阻塞。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是线程交互时,如果线程对一个同步对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">x </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">发出一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十三,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Java</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">goto?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Goto—java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中的保留字,现在没有在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中使用。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十四,数组有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? String</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">数组没有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法,有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的属性。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>String</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十五,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overload</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Override</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的区别。</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是否可以改变返回值的类型</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法的重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">多态性的不同表现。重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是父类与子类之间多态性的一种表现,重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> (Overriding)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">屏蔽</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(Overloading)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是可以改变返回值的类型。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十六,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Set</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用什么方法来区分重复与否呢</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是用</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">==</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">还是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">equals()? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">它们有何区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">iterator()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法来区分重复与否。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是判读两个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否相等。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">==</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法决定引用值是否指向同一对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十七,给我一个你最常见到的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">runtime exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, <br/>ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十八,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">error</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>error </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出。不可能指望程序能处理这样的情况。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>exception </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十九,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">List, Set, Map</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否继承自</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Collection</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">List</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,Map</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不是</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">interface</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">声明方法的存在而不去实现它的类被叫做抽象类(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">interface</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static final</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">instanceof </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">运算符可以用来决定某对象的类是否实现了接口。</span></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? short s1 = 1; s1 += 1;</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么错</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>short s1 = 1; s1 = s1 + 1;</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有错,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1+1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">int</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能显式转化为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">型。可修改为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">s1 =(short)(s1 + 1) </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">short s1 = 1; s1 += 1</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正确。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十二,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">sleep() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;"> wait() </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">搞线程的最爱</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法是使线程停止一段时间的方法。在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">sleep </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">时间间隔期满后,线程不一定立即恢复执行。这是因为在那个时刻,其它线程可能正在运行而且没有被调度为放弃执行,除非</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(a)“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">醒来</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的线程具有更高的优先级</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(b)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">正在运行的线程因为其它原因而阻塞。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是线程交互时,如果线程对一个同步对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">x </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">发出一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">wait()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十三,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Java</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">goto?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Goto—java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中的保留字,现在没有在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">中使用。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十四,数组有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? String</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有没有</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">length()</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">数组没有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法,有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的属性。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>String</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">length()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十五,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overload</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Override</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的区别。</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是否可以改变返回值的类型</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法的重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">多态性的不同表现。重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是父类与子类之间多态性的一种表现,重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> (Overriding)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">“</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">屏蔽</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">”</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(Overloading)</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloaded</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的方法是可以改变返回值的类型。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十六,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Set</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用什么方法来区分重复与否呢</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是用</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">==</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">还是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">equals()? </span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">它们有何区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的元素是不能重复的,那么用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">iterator()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法来区分重复与否。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是判读两个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否相等。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">==</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法决定引用值是否指向同一对象</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">equals()</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十七,给我一个你最常见到的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">runtime exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, <br/>ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十八,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">error</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">exception</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>error </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出。不可能指望程序能处理这样的情况。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>exception </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第十九,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">List, Set, Map</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否继承自</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Collection</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">List</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Set</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,Map</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不是</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">interface</span><span style="COLOR: sienna; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有什么区别</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?<br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">声明方法的存在而不去实现它的类被叫做抽象类(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract class</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Abstract </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">interface</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static final</span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">instanceof </span><span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">运算符可以用来决定某对象的类是否实现了接口。</span></p> <span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;"><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">abstract</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">method</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否可同时是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">static,</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否可同时是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">native</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,是否可同时是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">synchronized?<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">都不能</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十二,接口是否可继承接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">抽象类是否可实现</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">(implements)</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">抽象类是否可继承实体类</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">(concrete class)?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口可以继承接口。抽象类可以实现</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(implements)</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口,抽象类是否可继承实体类,但前提是实体类必须有明确的构造函数。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;"> </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十三,启动一个线程是用</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">run()</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">还是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">start()?<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">启动一个线程是调用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">start()</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法,使线程所代表的虚拟处理机处于可运行状态,这意味着它可以由</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">JVM</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">调度并执行。这并不意味着线程就会立即运行。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">run()</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法可以产生必须退出的标志来停止一个线程。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十四,构造器</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Constructor</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否可被</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">override?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">构造器</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Constructor</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能被继承,因此不能重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,但可以被重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十五,是否可以继承</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">String</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>String</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">final</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类故不可以继承。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十六,当一个线程进入一个对象的一个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">synchronized</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法后,其它线程是否可进入此对象的其它方法</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能,一个对象的一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">synchronized</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法只能由一个线程访问。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="MARGIN: 0cm 0cm 0pt;"></p></span> <span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;"><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">abstract</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">method</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否可同时是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">static,</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否可同时是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">native</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,是否可同时是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">synchronized?<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">都不能</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十二,接口是否可继承接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">抽象类是否可实现</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">(implements)</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">? </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">抽象类是否可继承实体类</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">(concrete class)?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口可以继承接口。抽象类可以实现</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">(implements)</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">接口,抽象类是否可继承实体类,但前提是实体类必须有明确的构造函数。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;"> </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十三,启动一个线程是用</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">run()</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">还是</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">start()?<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">启动一个线程是调用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">start()</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法,使线程所代表的虚拟处理机处于可运行状态,这意味着它可以由</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">JVM</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">调度并执行。这并不意味着线程就会立即运行。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">run()</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法可以产生必须退出的标志来停止一个线程。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十四,构造器</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Constructor</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否可被</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">override?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">构造器</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Constructor</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能被继承,因此不能重写</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overriding</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,但可以被重载</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Overloading</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十五,是否可以继承</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">String</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>String</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">final</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">类故不可以继承。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十六,当一个线程进入一个对象的一个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">synchronized</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法后,其它线程是否可进入此对象的其它方法</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不能,一个对象的一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">synchronized</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法只能由一个线程访问。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="MARGIN: 0cm 0cm 0pt;"></p></span> <span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span><p></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十七,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">try {}</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里有一个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">return</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">语句,那么紧跟在这个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">try</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">后的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">finally {}</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">code</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">会不会被执行,什么时候被执行,在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">return</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">前还是后</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">会执行,在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">return</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">前执行。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十八,编程题</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">: </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">用最有效率的方法算出</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">2</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">乘以</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">8</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">等於几</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">C</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">背景的程序员特别喜欢问这种问题。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">2 << 3</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十九,两个对象值相同</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">(x.equals(y) == true)</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,但却可有不同的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">hash code</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,这句话对不对</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不对,有相同的</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">hash code</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第三十,当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是值传递。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">编程语言只由值传递参数。当一个对象实例作为一个参数被传递到方法中时,参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变,但对象的引用是永远不会改变的。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> <br/></span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第三十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">swtich</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否能作用在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">byte</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">上,是否能作用在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">long</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">上,是否能作用在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">String</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">上</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>switch</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">expr1</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">)中,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">expr1</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是一个整数表达式。因此传递给</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> switch </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> case </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">语句的参数应该是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> int</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">、</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> short</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">、</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> char </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">或者</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> byte</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">long,string </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">都不能作用于</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">swtich</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第三十二,编程题</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">: </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">写一个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Singleton</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">出来。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/> Singleton</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">模式主要作用是保证在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">应用程序中,一个类</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Class</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">只有一个实例存在。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">一般</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Singleton</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">模式通常有几种种形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">:<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第一种形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">: </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">定义一个类,它的构造函数为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的,它有一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的该类变量,在类初始化时实例话,通过一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">public</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">getInstance</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法获取对它的引用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">继而调用其中的方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>public class Singleton {<br/>private Singleton(){}<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">在自己内部定义自己一个实例,是不是很奇怪?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">注意这是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">只供内部调用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>private static Singleton instance = new Singleton();<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这里提供了一个供外部访问本</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">class</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的静态方法,可以直接访问</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
<br/>public static Singleton getInstance() {<br/>return instance; <br/>} <br/>} <br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二种形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">: <br/>public class Singleton { <br/>private static Singleton instance = null;<br/>public static synchronized Singleton getInstance() {<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法比上面有所改进,不用每次都进行生成对象,只是第一次</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">使用时生成实例,提高了效率!</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>if (instance==null)<br/>instance</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">=</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">new Singleton();<br/>return instance; } <br/>} <br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">其他形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">:<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">定义一个类,它的构造函数为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的,所有方法为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">一般认为第一种形式要更加安全些</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;">
<p></p></span></p><p style="MARGIN: 0cm 0cm 0pt;"></p></span> <span style="COLOR: #333333; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;"><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span><p></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十七,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">try {}</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里有一个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">return</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">语句,那么紧跟在这个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">try</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">后的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">finally {}</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">里的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">code</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">会不会被执行,什么时候被执行,在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">return</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">前还是后</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">会执行,在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">return</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">前执行。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十八,编程题</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">: </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">用最有效率的方法算出</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">2</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">乘以</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">8</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">等於几</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">有</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">C</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">背景的程序员特别喜欢问这种问题。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">2 << 3</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二十九,两个对象值相同</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">(x.equals(y) == true)</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,但却可有不同的</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">hash code</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">,这句话对不对</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">不对,有相同的</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">hash code</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第三十,当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是值传递。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">编程语言只由值传递参数。当一个对象实例作为一个参数被传递到方法中时,参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变,但对象的引用是永远不会改变的。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> <br/></span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第三十一,</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">swtich</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是否能作用在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">byte</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">上,是否能作用在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">long</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">上,是否能作用在</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">String</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">上</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>switch</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">(</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">expr1</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">)中,</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">expr1</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">是一个整数表达式。因此传递给</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> switch </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">和</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> case </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">语句的参数应该是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> int</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">、</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> short</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">、</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> char </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">或者</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> byte</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">long,string </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">都不能作用于</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">swtich</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">。</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;"><p></p></span></p><p style="WORD-BREAK: break-all;"><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"> </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第三十二,编程题</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">: </span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">写一个</span><span lang="EN-US" style="COLOR: sienna; FONT-FAMILY: Arial;">Singleton</span><span style="COLOR: sienna; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">出来。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/> Singleton</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">模式主要作用是保证在</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Java</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">应用程序中,一个类</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Class</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">只有一个实例存在。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">一般</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">Singleton</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">模式通常有几种种形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">:<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第一种形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">: </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">定义一个类,它的构造函数为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的,它有一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的该类变量,在类初始化时实例话,通过一个</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">public</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">getInstance</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">方法获取对它的引用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">,</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">继而调用其中的方法。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>public class Singleton {<br/>private Singleton(){}<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">在自己内部定义自己一个实例,是不是很奇怪?</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">注意这是</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private </span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">只供内部调用</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>private static Singleton instance = new Singleton();<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这里提供了一个供外部访问本</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">class</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的静态方法,可以直接访问</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
<br/>public static Singleton getInstance() {<br/>return instance; <br/>} <br/>} <br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">第二种形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">: <br/>public class Singleton { <br/>private static Singleton instance = null;<br/>public static synchronized Singleton getInstance() {<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">这个方法比上面有所改进,不用每次都进行生成对象,只是第一次</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">
<br/>//</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">使用时生成实例,提高了效率!</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/>if (instance==null)<br/>instance</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">=</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">new Singleton();<br/>return instance; } <br/>} <br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">其他形式</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">:<br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">定义一个类,它的构造函数为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">private</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的,所有方法为</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;">static</span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">的。</span><span lang="EN-US" style="COLOR: #333333; FONT-FAMILY: Arial;"><br/></span><span style="COLOR: #333333; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial;">一般认为第一种形式要更加安全些</span><span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: #333333; FONT-FAMILY: Arial;">
<p></p></span></p><p style="MARGIN: 0cm 0cm 0pt;"></p></span> <p><a href="http://www.hzguigu.com/bbs"><font size="6">www.hzguigu.com/bbs</font></a></p><p></p> <font face="黑体" size="6">看不懂</font> 俺看不懂 饿,正在学吸粽…… <p><font color="#ff0000" size="7">到处溜达,到处瞎逛</font></p> <p>太牛B了点吧</p> <p>现需JSP高手另外再加会一门开发语言如VB来联系我,有两个小项目需要高手来完成。站内联系或QQ5828157</p>
页:
[1]