查漏補缺2(面試小題目),查漏補缺2面試題目

來源:互聯網
上載者:User

查漏補缺2(面試小題目),查漏補缺2面試題目

//面試public class Main{class demo{}public static void main(String[] args){new demo();//報錯,因為主函數是靜態所以class demo要加static//static不能使用this}public  void show(){new demo();//前面實際上省略this}}


1.面試 多態和匿名內部類的結合


提問為什麼下述代碼編譯失敗?(據說掛了很多人)

class in{void set(){ Object obj = new Object()//匿名內部類的子類對象,並向上轉型為Object { public void show() { System.out.print("sdf"); } }; obj.show();//向上轉型,限制了子類對象的特有方法,所以編譯失敗}}public class Main{public static void main(String[] args){new in().set();}}

2.下述代碼列印什嗎?

class Fu{public Fu() {show();}void show(){System.out.println("呵呵");}}class Zi extends Fu{int num = 9;Zi(){System.out.println("子構造器..."+num);}void show(){System.out.println("shiow..."+num);}}public class Main{public static void main(String[] args){new Zi();}}

show。。。0
子構造器。。。9

為什嗎?

Zi()
{
實際上省略了,super();調用super,執行Fu構造器裡的show,而子類中有show方法,所以覆蓋執行子類的show,子類的num預設初始化是0,所以先列印show。。。0,然後num 可視初始化9,然後列印  子構造器。。。9
}


3.下面列印什嗎?

class Zi {int num = 9;{System.out.println("shiow..."+num);}Zi(){System.out.println("shiow2..."+num);}}public class Main{public static void main(String[] args){new Zi();}}



shiow...9
show2...9


4.下面列印什嗎?

class Fu{Fu() {System.out.println("fu++++++++");//3show();}void show(){System.out.print("hehe");}}class Zi extends Fu{int num = 9;{System.out.println("shiow..."+num);num = 10;}Zi(){super();//2//可視初始化 5//構造代碼塊初始化 6System.out.println("shiow2..."+num);//7}void show()//4{System.out.println("zi show..."+num);}}public class Main{public static void main(String[] args){new Zi();//1:num = 0}}

fu++++++++
zi show...0
shiow...9
shiow2...10

結合以上3、4兩例:

new Zi()的時,num是預設初始化0,現在執行Zi類的建構函式,然後super執行父類的建構函式,然後執行子類覆蓋的show,這時num還是0,然後num顯示初始化為9,然後執行代碼塊初始化,然後Zi()建構函式的show


代碼注釋的標號為執行順序



小升初面試題目

第一、一定要表現出自信
第二、說話要大聲,但不是嚷
第三、考試前要多做奧數題
第四、如果考官問你如何看待自己,要多說好處少說處, 但一定都要說,要客觀
第五、進去之後要問好,老師讓坐再座,並道謝,走時說再見

自我介紹,你的學習情況,
 
2個C面試題目

void bit_set(unsigned char *p_data,unsigned char position,bool flag)
{
int mask_open[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int mask_close[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
if (1==flag)
*p_data=(*p_data)|mask_open[8-position];
if (0==flag)
*p_data=(*p_data)|mask_close[8-position];
}

void RightLoopMove(char * pStr,unsigned short steps)
{
char *str_tmp=(char *)malloc(sizeof(*pStr));
*str_tmp=(*pStr);
int n= sizeof(*pStr);
for (int i=0;i<n-1;i++)
{
if (i<steps)
pStr[steps-i-1]=str_tmp[n-steps-1+i];
else
pStr[i]=str_tmp[i-steps];
}
}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.