av片一区二区三区-av片亚洲-av片免费看-av片免费观看-欧美视频色-欧美视频三区

當前位置:高考升學網 > 招聘筆試題 > 正文

Java經典筆試題和面試題答案(二)

更新:2023-09-15 21:08:46 高考升學網

  16. 1) public class Test{

  2) public static void main(String args[]){

  3) int i =0xFFFFFFF1;

  4) int j=~i;

  5)

  6) }

  7) }

  which is decimal value of j at line 5?

  A. 0 B.1 C.14 D.-15 E. compile error at line 3 F. compile error at line 4

  Answer:C 分析:int是32位的(范圍應該在-231~231-1),按位取反后,后4位是1110,前面的全部是0,所以肯定是14

  17. float f=4.2F;

  Float g=new Float(4.2F);

  Double d=new Double(4.2);

  Which are true?

  A. f==g B. g==g C. d==f D. d.equals(f) E d.equals(g) F. g.equals(4.2);

  Answer:B,E(網上的答案是B,E;我測試的結果是:true,true,false,false,fasle,fasle,所以答案是:A,B,還請各位大蝦明示)

  分析:以下是我從網絡上找到的,但是感覺應用到這個題目上反而不對拉,郁悶中,希望能給大家有所提示,要是你們明白拉,記得給我留言啊!:~

  1.基本類型、對象引用都在棧中; 而對象本身在堆中;

  2.“==“比的是兩個變量在棧內存中的值,而即使變量引用的是兩個對象,“==”比的依舊是變量所擁有的“棧內存地址值”;

  3.equals()是每個對象與生俱來的方法,因為所有類的最終基類就是Object(除去Object本身);而equals()是Object的方法之一,也就是說equals()方法來自Object類。 觀察一下Object中equals()的source code:

  public boolean equals(Object obj) { return (this == obj); }

  注意:“return (this == obj)” this與obj都是對象引用,而不是對象本身。所以equals()的缺省實現就是比較“對象引用”是否一致,所以要比較兩個對象本身是否一致,須自己編寫代碼覆蓋Object類里的equals()的方法。來看一下String類的equals方法代碼:

  public boolean equals(Object anObject){

  if(this == anObject){

  return true;

  }

  if(anObject instanceof String){

  String anotherString = (String)anObject;

  int n = count;

  if(n == anotherString.count){

  char v1[] = value;

  char v2[] = anotherString.value;

  int i = offset;

  int j = anotherString.offset;

  while(n-- != 0){

  if(v1[i++] != v2[j++])

  return false;

  }

  return true;

  }

  }

  return false;

  }

  18. public class Equals{

  public static void add3(Integer i){

  int val = i.intValue();

  val += 3;

  i = new Integer(val);

  }

  public static void main(String args[]){

  Integer i=new Integer(0);

  add3(i);

  System.out.println(i.intValue());

  }

  }

  what is the result?

  A. compile fail B.print out "0" C.print out "3"

  D.compile succeded but exception at line 3

  Answer:B 分析:java只有一種參數傳遞方式,那就是值傳遞.(大家可以看我轉載的另一個同名文章,會讓大家豁然開朗)

  19. public class Test{

  public static void main(String[] args){

  System.out.println(6^3);

  }

  }

  what is output? Answer:5 分析: ^ is yi huo(計算機器上是Xor) ;異或的邏輯定義:真^真=假 真^假=真 假^真=真 假^假=假

  20. public class Test{

  public static void stringReplace(String text){

  text=text.replace('j','l');

  }

  public static void bufferReplace(StringBuffer text){

  text=text.append("c");

  }

  public static void main(String args[]){

  String textString=new String("java");

  StringBuffer textBuffer=new StringBuffer("java");

  stringReplace(textString);

  bufferReplace(textBuffer);

  System.out.println(textString+textBuffer);

  }

  }

  what is the output?

  Answer:javajavac

  分析:根據我轉載的一篇文章可以得出答案,不過還有幾個類似的題目,用該文章解釋不通,因為本人對java傳遞參數也一直沒有弄明白,所以,還請大蝦多多指教.

  21. public class ConstOver{

  public ConstOver(int x, int y, int z){}

  }

  which two overload the ConstOver constructor?

  A.ConstOver(){}

  B.protected int ConstOver(){}  //not overload ,but no a error

  C.private ConstOver(int z, int y, byte x){}

  D.public void ConstOver(byte x, byte y, byte z){}

  E.public Object ConstOver(int x, int y, int z){}

  Answer:A,C

  分析:測試不通過的首先是B,E,因為要求有返回值,這2個選項沒有,要想通過編譯那么需要加上返回值,請注意如果加上返回值,單純看選項是沒有問題拉,可以針對題目來說,那就是錯之又錯拉,對于構造器來說是一種特殊類型的方法,因為它沒有返回值.對于D選項在91頁有詳細的介紹,空返回值,經管方法本身不會自動返回什么,但可以選擇返回別的東西的,而構造器是不會返回任何東西的,否則就不叫構造器拉.

  22. public class MethodOver{

  public void setVar(int a, int b, float c){}

  }

  which overload the setVar?

  A.private void setVar(int a, float c, int b){}

  B.protected void setVar(int a, int b, float c){}

  C.public int setVar(int a, float c, int b){return a;}

  D.public int setVar(int a, float c){return a;}

  Answer:A,C,D 分析:方法的重載,根據概念選擇,B是錯誤的,因為他們有相同的參數列表,所以不屬于重載范圍.

  23. class EnclosingOne{

  public class InsideOne{}

  }

  public class InnerTest{

  public static void main(String args[]){

  EnclosingOne eo=new EnclosingOne();

  //insert code here

  }

  }

  A.InsideOne ei=eo.new InsideOne();

  B.eo.InsideOne ei=eo.new InsideOne();

  C.InsideOne ei=EnclosingOne.new InsideOne();

  D.InsideOne ei=eo.new InsideOne();

  E.EnclosingOne.InsideOne ei=eo.new InsideOne();

  Answer:E

  24. What is "is a" relation?

  A.public interface Color{}

  public class Shape{private Color color;}

  B.interface Component{}

  class Container implements Component{ private Component[] children; }

  C.public class Species{}

  public class Animal{private Species species;}

  D.interface A{}

  interface B{}

  interface C implements A,B{}  //syntex error

  Answer:B 我沒有明白這個題目的意思,有人能告訴我嘛?

  25. 1)package foo;

  2)

  3)public class Outer{

  4) public static class Inner{

  5) }

  6)}

  which is true to instantiated Inner class inside Outer?

  A. new Outer.Inner()

  B. new Inner()

  Answer:B

  if out of outerclass A is correct 分析:在Outer內部,B方式實例化內部類的方法是正確的,如果在Outer外部進行inner的實例化,那么A方法是正確的.

最新圖文

2020年河北新聞網兩學一做

時間:2023-09-18 07:0:24

2020年河北新聞網兩學一做

時間:2023-09-15 11:0:59

兩學一做學習教育知

時間:2023-09-21 06:0:30

2020年開展兩學一做學習教

時間:2023-09-19 21:0:30
主站蜘蛛池模板: 免费观看污视频网站| 微信头像2024年最新版图片男| 不纽扣的女孩| 子宫在肚子的哪个位置| 座头市 电影| 大侠霍元甲演员表| 荒岛大逃亡电影| 常宝霆| 风筝 电影| 晓彤| 第一财经直播电视直播| 孕妇直播肚子疼揉肚子| 媚狐传| 五的词语| 菲律宾电影毕业生代表| 爱欲1990未删减版播放| 张艺宣| 张咏咏| 北京卫视节目单全天| 陕09j01图集| 健步如飞的蜗牛三年级作文| 秀人网美女屋| 金燕子| 小绿人| 一路狂奔| 免费看污污的视频| 视频一区二| 赵立军| 韩剧上流社会| 王春晖| 1—36集电视剧在线观看| 曹查理电影大全免费观看国语| 篱笆墙的影子歌词| 高冷女头| 谢承均| 迷失之城剧情介绍| 易烊千玺个人资料简介| 故乡别来无恙演员表名单| 豪勇七蛟龙 电影| 细菌大战2| 战地天使|