class A{protected int method1(int a,int b){return 0;}}Which two are valid in a class that extends class A?哪兩項(xiàng)正確,為什么?A.public int method1(int a,int b){return 0;} ivate int method1(int a,int b){return 0;} ivate int method1(int a,long b){return 0;}D.public short method1(int a,int b){return 0;} atic protected int method1(int a,int b){return 0;}
熱心網(wǎng)友
抱歉應(yīng)該是 A C繼承父類是有條件的,這道題應(yīng)該考的是Java中的覆蓋和重載,B屬于覆蓋,但是覆蓋必須滿足子類的限制域大于父類的域,比如C中的private屬性是比其父類中protected屬性使用范圍更大的的限制域。而C很明顯是重載,看上去雖然是和父類函數(shù)一樣,但是其入口參數(shù)不同(一個(gè)是2個(gè)Int型,一個(gè)是1個(gè)Int型1個(gè)Long型),Java是將其作為兩個(gè)不同函數(shù)來處理的。