免费人成视频19674试看,精品三级在线观看视频,女百合互慰高潮在线观看,2020欧美一级高清片,播放日韩大片日韩大片中文字幕,欧美日韩久久黄片,a级免费按摩黄片

當(dāng)前位置:高考升學(xué)網(wǎng) > 招聘筆試題 > 正文

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

更新:2023-09-15 21:08:46 高考升學(xué)網(wǎng)

  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位的(范圍應(yīng)該在-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(網(wǎng)上的答案是B,E;我測試的結(jié)果是:true,true,false,false,fasle,fasle,所以答案是:A,B,還請各位大蝦明示)

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

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

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

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

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

  注意:“return (this == obj)” this與obj都是對象引用,而不是對象本身。所以equals()的缺省實現(xiàn)就是比較“對象引用”是否一致,所以要比較兩個對象本身是否一致,須自己編寫代碼覆蓋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只有一種參數(shù)傳遞方式,那就是值傳遞.(大家可以看我轉(zhuǎn)載的另一個同名文章,會讓大家豁然開朗)

  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

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

  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個選項沒有,要想通過編譯那么需要加上返回值,請注意如果加上返回值,單純看選項是沒有問題拉,可以針對題目來說,那就是錯之又錯拉,對于構(gòu)造器來說是一種特殊類型的方法,因為它沒有返回值.對于D選項在91頁有詳細(xì)的介紹,空返回值,經(jīng)管方法本身不會自動返回什么,但可以選擇返回別的東西的,而構(gòu)造器是不會返回任何東西的,否則就不叫構(gòu)造器拉.

  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 分析:方法的重載,根據(jù)概念選擇,B是錯誤的,因為他們有相同的參數(shù)列表,所以不屬于重載范圍.

  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內(nèi)部,B方式實例化內(nèi)部類的方法是正確的,如果在Outer外部進行inner的實例化,那么A方法是正確的.

最新圖文