freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

java程序設(shè)計教學(xué)課件第四章-在線瀏覽

2024-09-11 16:12本頁面
  

【正文】 urn hour+:+min+:+sec 。 public void init( ){ t=new time( )。 ( time:+( ),25,45)。例如: class point { int x, y。 } point(int a, int b){ x=a。 } } 29 繼承 ? 繼承是軟件重用的一種形式 , 可以提高系統(tǒng)的性能 ; ? Java不支持多繼承,但支持多接口; ? 子類的對象也是其超類的對象,反之未必; ? 繼承具有傳遞性。 point(int x, int y){ =x。 } point( ){ =0。 } } class circle extends point{ int radius。 =x。 } } 31 關(guān)鍵字 super ? 構(gòu)造函數(shù)是一種特殊的方法,子類不能繼承超類的構(gòu)造函數(shù),但子類構(gòu)造函數(shù)可以通過 super調(diào)用超類的構(gòu)造函數(shù)。例如: class point{ // 程序 48 int x, y。 =y。 } } class circle extends point{ int radius。 radius=r。 } } public class testInherence { public static void main(String args[ ]) { circle c1。 } } 34 再次討論構(gòu)造函數(shù) ? 若父類沒有定義構(gòu)造函數(shù),那么對父類數(shù)據(jù)的初始化將采用系統(tǒng)缺省的構(gòu)造函數(shù);例如: class point{ int x, y。 circle(int r, int x, int y){ =x。 radius=r。例如: class point{ int x, y。 } point(int x, int y){ =x。 } } class circle extends point{ // 注意子類的構(gòu)造函數(shù) int radius。 } } 36 再次討論構(gòu)造函數(shù)(續(xù)) ? 若父類定義的構(gòu)造函數(shù)都是有參的,那么子類構(gòu)造函數(shù)必須通過 super調(diào)用父類構(gòu)造函數(shù),例如: class point{ private int x, y。 =y。 circle(int r, int x, int y){ super(x, y)。 } } 37 方法的覆蓋 ? 方法的 覆蓋發(fā)生在父類和子類之間 ,若子類中定義的某個方法的特征,與父類中定義的某個方法的特征完全一樣,那么就說子類中的這個方法覆蓋了父類對應(yīng)的那個方法。 ? 覆蓋特點:子類中的方法特征與父類定義的 對應(yīng)方法的 特征完全一樣。 point( ){ this(0,0)。 =y。 } } class circle extends point{ int radius。 radius=r。 } } public class testOverWrite { public static void main(String args[ ]) { circle c1。 (( ))。 Java用此標(biāo)識在運行時選擇正確的方法。 point( ){ this(0,0)。 =y。} } class circle extends point{ int radius。 radius=r。 } } public class dynamicalCall { public static void main(String args[ ]) { point p[ ]={new point(2,2), new circle(1,1,1) }。i。 (“父類: ” + p[i].getClass( ).getsuperclass( ))。 } } } 44 方法的動態(tài)調(diào)用小節(jié) ? 子類對象調(diào)用方法時 (1) 子類檢查是否具有同名和同參數(shù)類型的方法 , 若有調(diào)用該方法 , 否則繼續(xù)執(zhí)行 。若找不到 , 將產(chǎn)生編譯錯誤 。 45 多態(tài)性不適合繼承鏈中的實例變量 ? 對象 .方法: 根據(jù)多態(tài)性調(diào)用; ? 對象 .實例變量:根據(jù)對象的類型調(diào)用。例如: class Base{ // 程序 412 int x=1。 (對象的 x= +this. x )。 void print( ){ (“當(dāng)前類為 ” + ( ).getName( ))。 } } public class confusions{ public static void main(String [ ] args){ Base obj=new Derived( )。 (對象的 x= +)。 ? 垃圾回收器是一個優(yōu)先級比較低的線程,在系統(tǒng)空閑時運行。 例如: class point{ // 程序 413 int x, y。 y=b。 } public void finalize( ){ // 注意該方法 (point finalizer:+getString( ))。 } } class circle extends point{ int radius。 radius=r。 } public void finalize( ){ (circle finalizer:+getString( ))。 } } public class testFinalize { public static void main(String args[ ]) { point c1,c2。 c2=new circle(2,2,2)。 c2=null。 } } 程序運行結(jié)果: point constructor: x=1 y=1 radius=0 circle constructor: x=1 y=1 radius=1 point constructor: x=2 y=2 radius=0 circle constructor: x=2 y=2 radius=2 circle finalizer : x=1 y=1 radius=1 circle finalizer : x=2 y=2 radius=2 52 static ? static修飾 變量(與 C中的不同) ; ? static修飾 方法(與 C中的不同) ; 53 static變量 ? static變量是指這樣的成員變量:不管在程序運行中生成多少個該類的對象 , 它們都共享該變量 。 因此 ,static變量又稱為類變量 。 ? static變量和一般的實例變量不同 , 在構(gòu)造函數(shù)中不能對它進(jìn)行初始化 。 int x, y。 (static variable is initialized !)。 x=a。 (Call point constructor!)。 (There are + + points)。 ? 在子類中不能覆蓋父類中定義的靜態(tài)方法 。并且還不能使用 this和 super。 // 定義靜態(tài)變量 int x, y。 (static variable is initialized !)。 x=a。 (Call point constructor!)。 } } public class testStaticMethod { public static void main(String arg
點擊復(fù)制文檔內(nèi)容
公司管理相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1