(3s4)Given:1. class Dims {
2.   public static void main(String[] args) {
3.     int[] [] a = {{1,2,}, {3,4}};
4.     int [] b = (int [] ) a [1] ;
5.     Object o1 = a;
6.     int [] [] a2 = (int[] [] )   o1;
7.     int [] b2 = (int []) o1;
8.     System.out.println(b[1]);
9. } }What is the result?A 2B 4C An exception is thrown at runtime.D Compilation fails due to an error on line 4.E Compilation fails due to an error on line 5.F Compilation fails due to an error on line 6.G Compilation fails due to an error on line 7.(3S6)
Given:
class Mixer {
  Mixer() { }
  Mixer(Mixer m) { ml = m;}
  Mixer m1;
  public static void main(String[] args) {
    Mixer m2 = new Mixer();
    Mixer m3 = new Mixer(m2);  m3.go();
    Mixer m4 = m3.m1;          m4.go();
    Mixer m5 = m2.m1;          m5.go();
  }
  void go() { System.out.print("hi "); }
}What is the result?A hi B hi hi C hi hi hi D Compilation failsE hi, followed by an exceptionF hi hi, followed by an exception
(3S8)
Given:class Fizz {
  int x = 5;
  public static void main(String[] args) {
    final Fizz f1 = new Fizz();
    Fizz f2 = new Fizz();
    Fizz f3 = FizzSwitch(f1,f2);
    System.out.println((f1 == f3) + " " + (f1.x == f3.x));
  }
  static Fizz FizzSwitch(Fizz x, Fizz y) {
    final Fizz z = x;
    z.x = 6;
    return z;
} }What is the result?A true true B false true C true false D false false E Compilation fails.F An exception is thrown at runtime.
(3S12)
Given:1. class Eco {
2.   public static void main(String[] args)    {
3.     Eco e1 = new Eco();
4.     Eco e2 = new Eco();
5.     Eco e3 = new Eco();
6.     e3.e = e2;
7.     e1.e = e3;
8.     e2 = null;
9.     e3 = null;
10.    e2.e = el;
11.    e1   =  null;
12.  }
13.  Eco e;
14. }At what point is only a single object eligible for GC?A After line 8 runs.B After line 9 runs.C After line 10 runs.D After line 11 runs.E Compilation fails.F Never in this program.G An exception is thrown at runtime.
(4S4)
Given:class  Fork {
  public static void main(String[] args)    {
    if(args.length == 1 | args[1] .equals("test")) {
      System.out.println ("test  case");
    } else {
      System.out.println("production " + args[0]) ;
    }
  }
}
And the command-line invocation:java Fork live2What is the result?A test case B production C test case live2 D Compilation fails.E An exception is thrown at runtime
(5S6)
Given:class Plane {
  static String s = "-";
  public static void main(String[] args) {
    new Plane().s1() ;
    System.out.println(s);
  }
  void sl() {
    try { s2();
    catch (Exception e) { s += "c"; }
  }
  void s2() throws Exception  {
    s3();  s += "2";
    s3();  s += "2b";
  }
  void s3() throws Exception {
    throw new Exception();
  }
}What is the result?A -B -c C -c2 D -2c E -c22b F -2c2b G -2c2bc H Compilation fails.
(5S8)
Given: 1. class Ping extends Utils {
 2.   public static void main(String [] args) {
 3.     Utils u = new Ping();
 4.     System.out.print(u.getInt(args[0]));
 5.   }
 6.   int getInt(String arg) {
 7.     return Integer.parseInt(arg);
 8.   }
 9. }
10. class Utils {
11.   int getInt(String x) throws Exception { return 7; }
12. }And the following three possible changes:C1. Declare that main() throws an Exception.C2. Declare that Ping.getInt() throws an Exception.C3. Wrap the invocation of getInt() in a try / catch block.Which change(s) allow the code to compile? (Choose all that apply.)A Just C1 is sufficient.B Just C2 is sufficient.C Just C3 is sufficient.D Both C1 and C2 are required.E Both C1 and C3 are required.F Both C2 and C3 are required.G All three changes are required.
(5S10)
Given:class Circus {
  public static void main(String[] args) {
    int x = 9;
    int y = 6;
    for(int z = 0; z < 6; z++, y--) {
      if(x > 2)  x--;
      label:
        if(x > 5) {
          System.out.print(x + " "};
          --X;
          continue label;           }
         X--;
      }
   }
}What is the result?A 8 B 8 7 C 8 7 6 D Compilation fails.E An exception is thrown at runtime.
(5S15)
Given:class Mineral { }
class Gem extends Mineral { }
class Miner {
  static int x = 7;
  static String s = null;
  public static void getWeight(Mineral m) {
    int y = 0 / x;
    System.out.print(s + " ");
  }
  public static void main(String[] args) {
    Mineral[] ma = {new Mineral(), new Gem()};   for(Object o : ma)
     getWeight((Mineral) o);
  }
}And the command-line invocation:java Miner.javaWhat is the result?A null B null null C A ClassCastException is thrown.D A NullPointerException is thrown.E A NoClassDefFoundError is thrown.F An ArithmeticException is thrown.G An IllegalArgumentException is thrown.H An ArrayIndexOutOfBoundsException is thrown.(6S2)
Given:import java.io.*;
class Player {
  Player() { System.out.print("p"); }
}
class CardPlayer extends Player implements Serializable {
  CardPlayer() { System.out.print("c"); }
  public static void main(String[] args){
    CardPlayer cl = new CardPlayer();    try {
      FileOutputStream fos = new FileOutputStream("play.txt");
      ObjectOutputStream os = new ObjectOutputStream(fos);
      os.writeObject(c1);
      os.close() ;
      FileInputStream fis = new FileInputStream("play.txt");
      ObjectInputStream is = new ObjectInputStream(fis);
      CardPlayer c2 = (CardPlayer) is.readObject();
      is.close();
    } catch (Exception x ) { }
  }
}What is the result?A pc B pcc C pcp D pcpc E Compilation fails.F An exception is thrown at runtime.(6S6)
Given:import java.io.*;class Keyboard { }
public class Computer implements Serializable {
  private Keyboard k = new Keyboard();
  public static void main(String[] args)
    Computer c = new Computer();
    c.storeIt(c) ;
  }
  void storeIt(Computer c) {
    try {
      ObjectOutputStream os = new ObjectOutputStream(
         new FileOutputStream("myFile"));
      os.writeObject(c);
      os.close() ;
      System.out.println("done");
    } catch (Exception x) {System.out.println("exc"); } }
  }
}What is the result? (Choose all that apply.)A exc B done 
 
C Compilation fails.D Exactly one object is serialized.E Exactly two objects are serialized.(6S12)
Given:import java.io.*;
class Directories {
  static String [] dirs = {"dirl", "dir2"};
  public static void main(String [] args){
    for (String d : dirs) {      // insert code 1 here      File file = new File(path, args[0]) ;      // insert code 2 here
    }
  }
}and that the invocationjava Directories file2.txt
is issued from a directory that has two subdirectories "dir1" and "dir1", and that "dir1" has a file "file1.txt" and "dir2" has a file "file2.txt", and the output is "false true"; which set(s) of code fragments must be inserted? (Choose all that apply.)A String path = d;   System.out.print (file.exists() + " "); B String path = d;   System.out .print (file . isFile() + " "); C String path = File.separator + d;   System.out .print (file . exists() + " "); D String path = File.separator + d;   System.out.print(file.isFile() + 

解决方案 »

  1.   

    这么多啊!实在是不看不下去!眼晕拷到eclipse里跑一下来的比这快
      

  2.   

    第一题就有疑惑,数组和object之间转换有什么规则? 一维数组和二维数组能转换么?谁能帮忙解释下。
      

  3.   

    首先你需要明确一点: 
    Java中没有真正的二维数组,而是数组的数组。就是说Java中的数组可以不是规则的矩形。下面是示意图。 
    真正的二维数组(C语言中的):(3x5) 
    [] [] [] [] [] 
    [] [] [] [] [] 
    [] [] [] [] [] 
    数组的数组(Java中的二维):(3x?) 
    [] [] [] [] [] 
    [] [] [] [] [] [] 
    [] [] [] 
    -------------------------------------------------------------------- 
    下面是例子代码。 
    public class ArrayChange { 
    /*主方法,在主方法中定义二维数组,然后调用doWork方法进行转换*/ 
    public static void main(String[] args) { 
    int[][] array = new int[3][]; 
    array[0] = new int[]{1,2,3,4,5}; 
    array[1] = new int[]{6,7,8,9,10,11}; 
    array[2] = new int[]{12,13,14}; 
    int[] a = doWork(array); 

    /*进行转换的方法,参数为二维数组,返回值为一维数组*/ 
    public static int[] doWork(int[][] array) { 
    /*计算数组中元素的个数*/ 
    int totalLength = 0;//存放数组元素个数的变量 
    for (int i=0;i<array.length;i++) {//通过循环计算元素个数 
    totalLength = totalLength+array[i].length; 

    /*进行转换*/ 
    int[] a = new int[totalLength];//转换后的一维数组 
    int index = 0;//一维数组的索引,用于指定当前位置 
    for (int i=0;i<array.length;i++) {//通过循环进行转换 
    for (int j=0;j<array[i].length;j++) { 
    a[index] = array[i][j]; 
    index++; 


    return a; 


      

  4.   

    object是所有对象的顶级父类    当然什么都可以转换为Object
      

  5.   

    回4楼,数组可以和Object对象进行转换,但必须是和Object[]数组进行转换.
    比如 int[] a = new int[1];  Object[] obj = a;
      

  6.   

    看起来够多的,我跑了一下,有些还是不能肯定,我的答案是:
    3S4 :CG
    3S6 :F
    3S8 :A
    3S12:G
    4S4 :D
    5S6 :H
    5S8 :E(或者A),我不太肯定。
    5S10:D
    5S15:B
    6S2 :F
    6S6 :E
    6S12:C