![ava面向?qū)ο蠹夹g(shù).ppt_第1頁(yè)](http://file.renrendoc.com/FileRoot1/2019-5/15/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc1.gif)
![ava面向?qū)ο蠹夹g(shù).ppt_第2頁(yè)](http://file.renrendoc.com/FileRoot1/2019-5/15/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc2.gif)
![ava面向?qū)ο蠹夹g(shù).ppt_第3頁(yè)](http://file.renrendoc.com/FileRoot1/2019-5/15/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc3.gif)
![ava面向?qū)ο蠹夹g(shù).ppt_第4頁(yè)](http://file.renrendoc.com/FileRoot1/2019-5/15/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc4.gif)
![ava面向?qū)ο蠹夹g(shù).ppt_第5頁(yè)](http://file.renrendoc.com/FileRoot1/2019-5/15/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc/9a573e76-dc01-4cb0-86ce-b3d1a02b50fc5.gif)
已閱讀5頁(yè),還剩38頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
Java語(yǔ)言程序設(shè)計(jì) 對(duì)象和類 抽象數(shù)據(jù)類型 基本數(shù)據(jù)類型屬性操作自定義數(shù)據(jù)類型屬性 數(shù)據(jù)成員 操作 函數(shù)成員 定義方法 函數(shù)和子程序voidreturn參數(shù)列表 值傳遞和地址傳遞 基本數(shù)據(jù)類型值傳遞其它數(shù)據(jù)類型值里存放的是地址地址傳遞 數(shù)據(jù)隱藏 隱藏的意義正確的訪問封裝 屏蔽實(shí)現(xiàn)的細(xì)節(jié) 便于改變實(shí)現(xiàn)隱藏的實(shí)現(xiàn)privatedefaultpublic this引用 指代當(dāng)前對(duì)象獲取當(dāng)前對(duì)象的指針 classVariable intx 0 y 0 z 0 voidinit intx inty this x x this y y intz 5 System out println x x y y z z publicclassVariableTest publicstaticvoidmain String args Variablev newVariable System out println x v x v y v y z v z v init 20 30 System out println x v x v y v y z v z publicclassLeaf privateinti 0 Leafincrement i returnthis voidprint System out println i i publicstaticvoidmain String args Leafx newLeaf x increment increment increment print 重載方法名 方法名相同參數(shù)不同參數(shù)的個(gè)數(shù)不同參數(shù)的類型不同參數(shù)的類型次序不同不包括返回值 classMethodOverloading voidreceive inti System out println Receiveoneintdata voidreceive inti intj System out println Receivetwointdata voidreceive doubled System out println Receiveonedoubledata voidreceive Strings System out println ReceiveaString publicclassMethodOverloadingTest publicstaticvoidmain String args MethodOverloadingm newMethodOverloading m receive 1 m receive 1 2 m receive 3 14 m receive hello publicclassOverloadingOrder staticvoidprint Strings inti System out println String s int i staticvoidprint inti Strings System out println int i String s publicstaticvoidmain String args print Stringfirst 11 print 99 Intfirst 對(duì)象的構(gòu)造和初始化 初始化和初始化方法構(gòu)造方法 classRock Rock ThisistheconstructorSystem out println CreatingRock publicclassSimpleConstructor publicstaticvoidmain String args for inti 0 i 10 i newRock 對(duì)象的構(gòu)造和初始化 重載構(gòu)造方法 classRock Rock inti System out println CreatingRocknumber i publicclassSimpleConstructor publicstaticvoidmain String args for inti 0 i 10 i newRock i 對(duì)象的構(gòu)造和初始化 默認(rèn)構(gòu)造方法如果已經(jīng)定義了一個(gè)構(gòu)建器 無(wú)論是否有自變量 編譯程序都不會(huì)幫我們自動(dòng)合成一個(gè) finalize方法垃圾收集器 classPoint intx y Stringname apoint Point x 0 y 0 Point intx inty Stringname this x x this y y this name name intgetX returnx intgetY returny PointnewPoint Stringname PointnewP newPoint x y name returnnewP voidprint System out println name x x y y publicclassUsingObject publicstaticvoidmain String args Pointp newPoint p print Pointp1 newPoint 50 50 anewPoint p1 print System out println p1 x p1 y System out println p1 getX p1 getY p1 newPoint hello print newPoint 10 15 anothernewpoint print 子類 組合hasa繼承isaextends關(guān)鍵字protected單重繼承 classCleanser privateStrings newString Cleanser publicvoidappend Stringa s a publicvoiddilute append dilute publicvoidapply append apply publicvoidscrub append scrub publicvoidprint System out println s publicstaticvoidmain String args Cleanserx newCleanser x dilute x apply x scrub x print publicclassDetergentextendsCleanser publicvoidscrub append Detergent scrub super scrub publicvoidfoam append foam publicstaticvoidmain String args Detergentx newDetergent x dilute x apply x scrub x foam x print System out println Testingbaseclass Cleanser main args classArt Art System out println Artconstructor classDrawingextendsArt Drawing System out println Drawingconstructor publicclassCartoonextendsDrawing Cartoon System out println Cartoonconstructor publicstaticvoidmain String args Cartoonx newCartoon 多態(tài)性 向上映射instanceof運(yùn)算符對(duì)象轉(zhuǎn)換Shapes java 覆蓋方法 繼承的過程繼承全部?jī)?nèi)容增加內(nèi)容改變內(nèi)容覆蓋方法一致的聲明 名稱 參數(shù) 不低于基類的存取權(quán)限 java包 分割系統(tǒng)包package包的命名原則導(dǎo)入import與include環(huán)境變量 Java語(yǔ)言程序設(shè)計(jì) 異常處理 異常 什么是異常正常情況之外的一種 異常 在問題發(fā)生的時(shí)候 我們可能不知具體該如何解決 但肯定知道已不能不顧一切地繼續(xù)下去 此時(shí) 必須堅(jiān)決地停下來(lái) 并由某人 某地指出發(fā)生了什么事情 以及該采取何種對(duì)策 異常的分類 異常示例 publicclassHelloWorld publicstaticvoidmain Stringargs inti 0 Stringgreeting Helloworld No Imeanit HELLOWORD while i 4 System out println greeting i i 異常處理 try塊若位于一個(gè)方法內(nèi)部 并 擲 出一個(gè)違例 或在這個(gè)方法內(nèi)部調(diào)用的另一個(gè)方法產(chǎn)生了違例 那個(gè)方法就會(huì)在違例產(chǎn)生過程中退出 若不想離開方法 可在那個(gè)方法內(nèi)部設(shè)置一個(gè)特殊的代碼塊 用它捕獲違例 這就叫作 try塊 因?yàn)橐谶@個(gè)地方 嘗試 各種方法調(diào)用 try塊屬于一種普通的作用域 用一個(gè)try關(guān)鍵字開頭 try 可能產(chǎn)生違例的代碼 異常處理 catch生成的違例必須在某個(gè)地方中止 這個(gè) 地方 便是違例控制器或者違例控制模塊 而且針對(duì)想捕獲的每種違例類型 都必須有一個(gè)相應(yīng)的違例控制器 違例控制器緊接在try塊后面 且用catch 捕獲 關(guān)鍵字標(biāo)記 如下所示 try Codethatmightgenerateexceptions catch Type1id1 HandleexceptionsofType1 catch Type2id2 HandleexceptionsofType2 catch Type3id3 HandleexceptionsofType3 異常處理 捕獲所有違例catch Exceptione 這段代碼能捕獲任何違例 所以在實(shí)際使用時(shí)最好將其置于控制器列表的末尾 防止跟隨在后面的任何特殊違例控制器失效 publicclassExceptionMethods publicstaticvoidmain String args try thrownewException Here smyException catch Exceptione System out println CaughtException System out println e getMessage e getMessage System out println e toString e toString System out println e printStackTrace e printStackTrace 異常處理 finally無(wú)論一個(gè)違例是否在try塊中發(fā)生 我們經(jīng)常都想執(zhí)行一些特定的代碼 為達(dá)到這個(gè)目的 可在所有違例控制器的末尾使用一個(gè)finally從句 publicclassFinallyWorks staticintcount 0 publicstaticvoidmain String args while true try post incrementiszerofirsttime if count 0 thrownewException System out println Noexception catch Exceptione System out println Exceptionthrown finally System out println infinallyclause if count 2 break outof while 常見異常 ArithmetricExceptionNullPointerExceptionNegativeArraySizeExceptionArrayIndexOutOfBoundsExceptionSecurityExceptionIOException 拋出異常 異常的處理機(jī)制違例機(jī)制的一項(xiàng)好處就是能夠簡(jiǎn)化錯(cuò)誤控制代碼 我們?cè)僖膊挥脵z查一個(gè)特定的錯(cuò)誤 然后在程序的多處地方對(duì)其進(jìn)行控制 此外 也不需要在方法調(diào)用的時(shí)候檢查錯(cuò)誤 因?yàn)楸WC有人能捕獲這里的錯(cuò)誤 我們只需要在一個(gè)地方處理問題 違例控制模塊 或者 違例控制器 這樣可有效減少代碼量 并將那些用于描述具體操作的代碼與專門糾正錯(cuò)誤的代碼分隔開 拋出異常 創(chuàng)建自己的異常 為什么要?jiǎng)?chuàng)建異常創(chuàng)建異常代碼為創(chuàng)建自己的違例類 必須從一個(gè)現(xiàn)有的違例類型繼承 最好在含義上與新違例近似 產(chǎn)生異常thrownewmyExeption classMyExceptionextendsException publicMyException publicMyException Stringmsg super msg publicclassInheriting publicstaticvoidf throwsMyException System out println T
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年漿雜棉沙項(xiàng)目可行性研究報(bào)告
- 2025年中國(guó)折頁(yè)機(jī)行業(yè)市場(chǎng)調(diào)查研究及投資前景展望報(bào)告
- 河北成立叉車生產(chǎn)制造公司可行性報(bào)告
- 2025年中國(guó)華麗水晶門行業(yè)市場(chǎng)發(fā)展前景及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 面瓦楞夾芯板行業(yè)行業(yè)發(fā)展趨勢(shì)及投資戰(zhàn)略研究分析報(bào)告
- 2025年中國(guó)中小型農(nóng)具行業(yè)發(fā)展全景監(jiān)測(cè)及投資前景展望報(bào)告
- 2025年中國(guó)一次性紙餐具市場(chǎng)前景預(yù)測(cè)及投資規(guī)劃研究報(bào)告
- 2025-2030年中國(guó)燈具開發(fā)行業(yè)深度研究分析報(bào)告
- 2025年無(wú)防針織項(xiàng)目可行性研究報(bào)告
- 智能化檔案管理平臺(tái)-深度研究
- 二零二五年度大型自動(dòng)化設(shè)備買賣合同模板2篇
- 2024版金礦居間合同協(xié)議書
- GA/T 2145-2024法庭科學(xué)涉火案件物證檢驗(yàn)實(shí)驗(yàn)室建設(shè)技術(shù)規(guī)范
- 2025內(nèi)蒙古匯能煤化工限公司招聘300人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025年中國(guó)融通資產(chǎn)管理集團(tuán)限公司春季招聘(511人)高頻重點(diǎn)提升(共500題)附帶答案詳解
- 寵物護(hù)理行業(yè)客戶回訪制度構(gòu)建
- 電廠檢修管理
- 《SPIN銷售法課件》課件
- 機(jī)動(dòng)車屬性鑒定申請(qǐng)書
- 2024年中考語(yǔ)文試題分類匯編:非連續(xù)性文本閱讀(學(xué)生版)
- 門店禮儀培訓(xùn)
評(píng)論
0/150
提交評(píng)論