`

java 题集(三)

阅读更多

1. 本题要点: &是位运算符,表示按位与运算。左右式都要运算得到结果。
&&是逻辑运算符,表示逻辑与(and)。
 &&有个特性,那就是先计算左边的,如果左边的满足了,那么右边的式子就不用运算
public class Test{
private static int j=0;
public static boolean methodB(int k){
j+=k;
return true;
}
public static void methodA(int i){
boolean b;
b=i>10&methodB(1);
b=i>10&&methodB(2);
}
public static void main(String args){
methodA(0);
17)
}
}
what is the value of j at line 17?
1
2.本题知道super也就是继承的妈即可
class A{
public String toString(){
return "4";
}
}
class B extends A{
public String toString(){
return super.toString()+"3";
}
}
public class Test{
public static void main(String args){
B b=new B();
System.out.println(b.toString());
}
}
what is the result?
43
3. 本题很有迷惑性,其实重点不在于Runnable,而是在于传入的a.
    作为参数传入,传得是地址,而不是值。因此,实际上a的内部参数并没有改变。
class A implements Runnable{
public int i=1;
public void run(){
this.i=10;
}
}
public class Test{
public static void main(String args){
A a=new A();
11) new Thread(a).start();
int j=a.i;
13)
}
}
what is the value of j at line 13?
A. 1
B. 10
C. the value of j cannot be determined
D. An error at line 11 cause compilation to fail
A
4.本题要点:不同的系统不同的线程导致你不知道顺序启动的这两个线程当中的锁什么时候解开,什么时候锁上了。例如一开始锁掉了s1,s2。第二个thread的时候到底锁开了么,你不知道。
public class SyncTest{
public static void main(String[] args){
final StringBuffer s1=new StirngBuffer();
final StringBuffer s2=new StirngBuffer();
new Thread(){
public void run(){
Synchronized(s1){
s1.append("A");
Synchronized(s2){
s2.append("B");
System.out.print(s1);
System.out.print(s2);
}
}
}
}.start();
new Thread(){
public void run(){
Synchronized(s2){
s2.append("C");
Synchronized(s1){
s1.append("D");
System.out.print(s2);
System.out.print(s1);
}
}
}
}.start();
}
}
what is the result?
A.the result depends on different system and different thread model
B.the result cannot be determined
AB
5.没啥要说的
public class Test{
public static void main(String[] args){
String foo="blue";
String bar=foo;
foo="green";
System.out.println(bar);
}
}
what is the result?
blue
6. 都是util的。不管是Hashtable, Hashmap, Hashset.实现map
which interface Hashtable implements?
A. java.util.Map
B. java.util.List
C. java.util.Hashable
D. java.util.Collection
A
7.
which two are true?
A. static inner class requires a static initializer
B. A static inner class requires an instance of the enclosing class
C. A static inner class has no reference to an instance of the enclosing class
D. A static inner class has accesss to the non-static member of the other class
E. static members of a static inner class can be referenced using the class name of the static inner class
CE
8.
which two are true?
A. An anonymous inner class can be declared inside of a method
B. An anonymous inner class constructor can take arguments in some situations
C. An anonymous inner class that is a direct subclass of Object can implements multiple interface
D. Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements a single interface
E. Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements multipe interface
AB
9. 本题注意看清括号就可以了,继承的方法有效,当然,不可能是同型的,否则没法重载
class A{
public int getNumber(int a){
return a+1;
}
}
class B extends A{
public int getNumber(int a, char c){
return a+2;
}
public static void main(String[] args){
B b=new B();
14) System.out.println(b.getNumber(0));
}
}
what is the result?
A. compilation succeeds and 1 is printed
B. compilation succeeds and 2 is printed
C. An error at line 8 cause compilation to fail
D. An error at line 14 cause compilation to fail
A
10.没啥好说的,一个在panel上面,一个不在
import java.awt.*;
public class X extends Frame{
public static void main(String[] args){
X x=new X();
x.pack();
x.setVisible(true);
}
public X(){
setLayout(new BorderLayout());
Panel p=new Panel();
add(p,BorderLayout.NORTH);
Button b=new Button("North");
p.add(b);
Button b1=new Button("South");
add(b1,BorderLayout.SOUTH);
}
which two are true?
A. The button labeled "North" and "South" will have the same width
B. The button labeled "North" and "South" will have the same height
C. The height of the button labeled "North" can vary if the Frame is resized
D. The height of the button labeled "South" can vary if the Frame is resized
E. The width of the button labeled "North" is constant even if the Frame is resized
F. The width of the button labeled "South" is constant even if the Frame is resized
DE
11.在所提供的里面符合条件的是Map和它延伸的 SortedMap,此外还有HashMap和HashTable
which two interfaces provide the capability to store objects using a key-value pair?
A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.SortedSet
E. java.util.SortedMap
F. java.util.Collection
AE
12. 必须是final修饰的,然后final void static final void
which two declaretions prevent the overriding of a method?
A. final void methoda(){}
B. void final methoda(){}
C. static void methoda(){}
D. static final void methoda(){}
E. final abstract void methoda(){}
AD
13.
which two are true?
public class OuterClass{
private double d1=1.0;
//inser code here
}
A. static class InnerOne{
public double methoda(){return d1;}
B. static class InnerOne{
static double methoda(){return d1;}
C. private class InnerOne{
public double methoda(){return d1;}
D. protected class InnerOne{
static double methoda(){return d1;}
E. public abstract class InnerOne{
public abstract double methoda();

14.
You want a class to have access to members of another class in the same package which is the most restrictive access modifier that will accomplish
this objective?
A. public
B. private
C. protected
D. transient
E. No acess modifier is required
E
15.
which two statements declare an array capable of 10 ints?
A. int[] foo;
B. int foo[];
C. int foo[10];
D. Object[] foo;
E. Object foo[10];
AB
16.本题注意,如果没有break的话,那么会依次的执行后面的语句。
public class SwitchTest{
public static void main(String[] args){
3) System.out.println("value="+switchIt(4));
}
public static int switchIt(int x){
int j=1;
switch(x){
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j+x;
}
}
what is the output from line 3?
A. value=3 B. value=4 C. value=5
D. value=6 E. value=7 F. value=8
F
17.后半句说明是static的,这里只有一个。而且前半句提到包内有效,而default恰好是包内有效的。
which will declare a method that is available to all members of the same package and can be referenced without an instance of the class?
A. abstract public void methoda();
B. public abstract double methoda();
C. static void methoda(double d1){}
D. public native double methoda(){}
E. protected void methoda(double d1){}
C
18. 子类自然包含所有的父类
1)public class SuperClass{
2) class SubClassA extends SuperClass{}
3) class SubClassB extends SuperClass{}
4) public void test(SubClassA foo){
5) SuperClass bar=foo;
6) }
7) }
which statement is true about the assignment in line 5?
A. The assignment in line 5 is illegal
B. The assignment in line 5 is legal, but throw a ClassCastException
C. legal and will always executes without throw an Exception
C
19.彻底封装的类,内部的乘员变量肯定访问不到private,只能通过借口方法访问和改变
which two are true to describe an entire encapsulation class?
A. member data have no access modifiers
B. member data can be modified directly
C. the access modifier for methods is protected
D. the access modifier to member data is private
E. methods provide for access and modification of data
DE
20.
public class X implements Runnable{
public static void main(String[] args){
3) //insert code
}
public void run(){
int x=0,y=0;
for(;;){
x++;
Y++;
System.out.println("x="+x+",y="+y);
}
}
}
which codes are added to line 3 to cause run() to be executed?
A. X x=new X();
x.run();
B. X x=new X();
new Thread(x).run();
C. X x=new X();
new Thread(x).start();
D. Thread t=new Thread(x).run();
E. Thread t=new Thread(x).start();
ABC
21.没有Diretory的哦
which gets the name of the parent directory of file "file.txt"?
A. String name=File.getParentName("file.txt");
B. String name=(new File("file.txt")).getParent();
C.String name=(new ile("file.txt")).getParentName();
D.String name=(new ile("file.txt")).getParentFile();
E.Diretory dir=(new ile("file.txt")).getParentDir();
String name=dir.getName();
B
22. FileOutputStream会干掉原来文件,弄出个0字节的,然后再往里填充数据
The file "file.txt" exists on the file system and contains ASCII text.
try{
File f=new File("file.txt");
OutputStream out=new FileOutputStream(f);
}catch (IOException e){}
A.the code does not compile
B.the code runs and no change is made to the file
C.the code runs and sets the length of the file to 0
D.An exception is thrown because the file is not closed
E.the code runs and deletes the file from the file system
C
23.
class Super{
public int i=0;
public Super(String text){
i=1;
}
}
public class Sub extends Super{
public Sub(String text){
i=2;
}
public static void main(String args[]){
Sub sub=new Sub("Hello");
System.out.println(sub.i);
}
}
what is the result?
A. compile will fail
B. compile success and print "0"
C. compile success and print "1"
D. compile success and print "2"
A
24.本题注意:显式的throw Exception的话,方法本身要有try catch或者最应该有throw出来,否则不能编译。
import java.io.IOException;
public class ExceptionTest{
public static void main(String args[]){
try{
methodA();
}catch(IOException e){
System.out.println("Caught Exception");
}
}
public void methodA(){
throw new IOException();
}
}
what is the result?
A.The code will not compile
B.The output is Caught Exception
C.The output is Caught IOException
D.The program executes normally without printing a message
A
25.
You are assigned the task of building a Panel containing a TextArea at the top, a Labbel directly bellow it, and a Button directly bellow the Label. If the three components added directly to the Panel. which layout manager can the Panel use to ensure that the TextArea absorbs all of the free vertical space when the Panel is resized?
A.GridLayout
B.CardLayout
C.FlowLayout
D.BorderLayout
E.GridbagLayout

26.
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be access in nature order, which interace provides that capability?
A. java.uil.Map
B.java.util.Set
C.java.util.List
D.java.util.SortedSet
E.java.util.SortedMap
F.java.util.Collection

27. which two cannot directly cause a thread to stop executing?
A.calling the yield method
B.calling the wait method on an object
C.calling the notify method on an object
D.calling the notifyAll method on an object
E.calling the start method on another thread object

CD

28.注意:继承了Runnable那么一定要有public void run() {}
1)public class Foo implements Runnable{
2) public void run(Thread t){
System.out.println("Running");
}
public static void main(String[] args){
new Thread(new Foo()).start();
}
}
what is the result?
A.An Exception is thrown
B.The program exits without printing anything
C.An error at line 1 causes complication to fail
D.An error at line 2 causes complication to fail
E."Running" is pinted and the program exits
C
29.
which method in the Thread class is used to create and launch a new thread of execution?
A.run() B.start() C. begin()
D.run(Runnable r) E.execute(Thread t)

30.
which is true?
A.If only one thread is blocked in the wait method of an object, and another thread executes the notify method on that same object,then the first thread immediately resumes executes.
B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object,it is still possible that the first thread might never resume execution
C.If a thread is blocked in the wait method of an object,and another thread executes the notify method on the same object,then the first thread definitely resumes execution as a direct and sole consequence of the notify call
D.If two threads are blocked in the wait method of one object,and another thread executes the notify method on the same object,then the thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call
ab
31.
which statement is true?
A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement mutiple interfaces
D. An anonymous inner class can access final variables in any enclosing scope
E. Construction of an instance of a static inner class requires an instance of the encloing outer class

32.
public class X{
public Object m(){
3)Object o=new Float(3.14f);
Object[] oa=new Object[1];
Oa[0]=0;
o=null;
return oa[0];
}
}
when is the float Object, created in line 3 ,collected as garbage?
A.just after line 5 B.just after line 6
C.just after line 7 D.never in this method

33.
which will declare a method that forces a subclass to implement?
A.public double methoda()
B.abstract public void methoda()
B
34. 本题要点:注意OutputStreamWriter其实已经由前缀的java.io指出了。而 PrintWriter却没有
//point X
public class Foo{
public static void main(String[] args){
PrintWriter out=new PrintWriter(new java.io.OutputStreamWriter(System.out),true);
out.println("Hello");
}
}
which statement at point X on line 1 allows this code to compile and run?
A.import java.io.PrintWriter
B.include java.io.PrintWriter
C.import java.io.OutputStreamWriter
D.include java.io.OutputStreamWriter
E.No statement is needed
A
35.这个没啥。其它的有些事.net的
Which of the following are Java keywords?
A) NULL (null)
B) new
C) instanceOf (inctanceof)
D) wend  (rubbish)
B
36.第一个run执行完之后开始执行第二个run
Given the following code:
1. public class MyThread implements Runnable {
2. private String holdA = "This is ";
3. private int[] holdB = {1,2,3,4,5,6,7,8,9,10};
4.
5. public static void main(String args[]) {
6. MyThread z = new MyThread();
7. (new Thread(z)).start();
8. (new Thread(z)).start();
9. }
10.
11. public synchronized void run() {
12. for(int w = 0;w < 10;w++) {
13. System.out.println(holdA + holdB[w] + ".");
14. }
15. }
16. }
What is the result?
A) Compilation fails because of an error on line 6.
B) Compilation fails because of an error on line 11.
C) Compilation fails because of errors on lines 7 and 8.
D) Compilation succeeds and the program prints each value in the holdB array at the end of the "This is" line. Each value is printed two times before the program ends, and the values are not printed in sequential order.
E) Compilation succeeds and the program prints each value in the holdB array at the end of the "This is" line. Each value is printed in order from 1 to 10, and after the value 10 prints, it starts printing the values 1 to 10 in order again.
E
37.默认使用unicode读写。FileReader extends InputStreamReader for file reading
You have an 8-bit file using the character set defined by ISO 8859-8. You are writing an application to display this file in a TextArea. The local encoding is already set to 8859-8. How can you write a chunk of code to read the first line from this file? You have three variables accessible to you:
myfile is the name of the file you want to read
stream is an InputStream object associated with this file
s is a String object
Select all valid answers.
A)
InputStreamReader reader = new InputStreamReader(stream, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
B)
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
C)
InputStreamReader reader = new InputStreamReader(myfile, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
D)
InputStreamReader reader = new InputStreamReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
E)
FileReader reader = new FileReader(myfile);()
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
AE
38.本题的迷惑性在于,T++都是先运行,再供判断的,也就是说m的值如何,if的结果是什么不影响t的值。但是知道for将运行4次,因此也将有4次t++。
Given the following code:
1. public class TeSet {
2. public static void main(String args[]) {
3. int m = 2;
4. int p = 1;
5. int t = 0;
6. for(;p < 5;p++) {
7. if(t++ > m) {
8. m = p + t;
9. }
10. }
11. System.out.println("t equals " + t);
12. }
13. }
What is the resulting value of t?
A) 2
B) 4
C) 6
D) 7
B
39.Map是一对一对的放入的
Which statement about the Map interface is true?
A) Entries are placed in a Map using the values() method.
B) Entries are placed in a Map using the entrySet() method.
C) A key/value association is added to a Map using the put() method.
D) A key/value association is added to a Map using the putAll() method.
C
40. Math.ceil(); //取最接近且最大的整数
Math.floor(); //取最接近且最小的整数
Math.abs (); //取正数
Given the following code:
1. public class GetIt {
2. public static void main(String args[]) {
3. double x[] = {10.2, 9.1, 8.7};
4. int i[] = new int[3];
5. for(int a = 0;a < (x.length);a++) {
6.
7.
System.out.println(“it is ”+i[a]);
8. }
9. }
10. }
The GetIt class should print like the following:
It is 11
It is 10
It is 9
Which line should you insert on line 6 to accomplish this?
A) i[a] = ((int)Math.min(x[a]));
B) i[a] = ((int)Math.max(x[a]));
C) i[a] = ((int)Math.ceil(x[a]));
D) i[a] = ((int)Math.floor(x[a]));
C
41. 调用obj的wait(), notify()方法前,必须获得obj锁,也就是必须写在synchronized(obj) {...} 代码段内
What statements are true concerning the method notify() that is used in conjunction with wait()?
Select all valid answers.
A) if there is more than one thread waiting on a condition, only the thread that has been waiting the longest is notified
B) if there is more than one thread waiting on a condition,there is no way to predict which thread will be notifed
C) notify() is defined in the Thread class
D) it is not strictly necessary to own the lock for the object you invoke notify()
E) notify() should only be invoked from within a while loop
BD
42.两种启动线程方式:Runnable a = new Runnable()
Thread a = new Thread()
注意后面都带上;号结尾。此外,若要继承Runnable接口,那么首先必须是个class,而且是.run()起来
Given the following class:
class Counter {
   public int startHere = 1;
   public int endHere = 100;
   public static void main(String[] args) {
      new Counter().go();
   }
   void go() {
      // A
      Thread t = new Thread(a);
      t.start();
   }
}
What block of code can you replace at line A above so that this program will count from startHere to endHere? Select all valid answers.
A)
Runnable a = new Runnable() {
   public void run() {
      for (int i = startHere; i <= endHere; i++) {
         System.out.println(i);
      }
   }
};
B)
a implements Runnable {
   public void run() {
      for (int i = startHere; i <= endHere; i++) {
         System.out.println(i);
      }
  }
};
C)
Thread a = new Thread() {
   public void run() {
      for (int i = startHere; i <= endHere; i++) {
         System.out.println(i);
      }
   }
};
AC
43.这个只好背下来
Why might you define a method as native? Select all valid answers.
A) To get to access hardware that Java does not know about
B) To define a new data type such as an unsigned integer
C) To write optimized code for performance in a language such as C/C++
D) To overcome the limitation of the private scope of a method
AC
44. 内隐类只能访问自己这条nested线的变量和方法,从enclosing type继承出去的已经不属于这条线了,所以不能直接访问。此题中,可以在method2中这样访问z: D d = new D(); d.z = 1;
Given the following class definition:
class A {
   public int x;
   private int y;
   class B {
      protected void method1() {
      }
      class C {
         private void method2() {
         }
      }
   }
}
class D extends A {
   public float z;
}
What can method2() access directly, without a reference to another instance? Select all valid answers.
A) the variable x defined in A
B) the variable y defined in A
C) method1 defined in B
D) the variable z defined in D
ABC
45.嵌套在方法中的类存取final类型??
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
A) The class can access any variable
B) The class can only access static variables
C) The class can only access transient variables
D) The class can only access final variables
D
46.对于obj来说 ==比较的是地址,而equals比较的是真正的值
What is written to the standard output as the result of executing the following statements?
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
if (b1 == b2)
    if (b1.equals(b2))
       System.out.println("a");
    else
       System.out.println("b");
else
   if (b1.equals(b2))
      System.out.println("c");
   else
      System.out.println("d");
Select the one right answer.
A) a
B) b
C) c
D) d
C
47.Switch的问题不重复了,注意选上这个switch是正常的选项
Examine the following switch block:
char mychar = `c`;
switch (mychar) {
   default:
   case `a`: System.out.println("a"); break;
   case `b`: System.out.println("b"); break;
}
Which of the following questions are definitely true? Select all valid answers.
A) This switch block is illegal, because only integers can be used in the switch statement.
B) This switch block is fine.
C) This switch block is illegal, because the default statement must come last.
D) When this code runs, nothing is written to the standard output.
E) When this code runs, the letter "a" is written to the standard output.
BE
48.原始类型有默认值,其它都是null或必须首先初始化。数组的数组,数组可以嵌套
Which statements accurately describe the following line of code?
String[][] s = new String[10][];
A) This line of code is illegal.
B) s is a two-dimensional array containing 10 rows and 10 columns
C) s is an array of 10 arrays.
D) Each element in s is set to ""
E) Each element in s is uninitialized and must be initialized before it is referenced.
CE
49.下划线,$也可以。数字和特殊符号肯定不可以作为变量的开头,这里还是存疑的,因为$题目中都认为不可以,但是实际使用时可以的,是不是jdk1.5和以前不同的关系。
Which of the following identifiers are ILLEGAL?
Select all valid answers.
A) #_pound
B) _underscore
C) 5Interstate
D) Interstate5
E) _5_
AC
50.注意,都必须有public void run()方法
What must be true for the RunHandler class so that instances of RunHandler can be used as written in the code below:
class Test {
   public static void main(String[] args) {
      Thread t = new Thread(new RunHandler());
      t.start();
   }
}
Select all valid answers.
A) RunHandler must implement the java.lang.Runnable interface.
B) RunHandler must extend the Thread class.
C) RunHandler must provide a run() method declared as public and returning void.
D) RunHandler must provide an init() method.
ABC
51.内部类可以是静态的,可能只有一个构造器,能够继承其它的类。但是不能是private的,可以是protected的
Which of the following statements are true? Select all valid answers.
A) An inner class may be defined as static
B) An inner class may NOT be define as private
C) An anonymous class may have only one constructor
D) An inner class may extend another class
ABCD
52.接口不能实例化,少import*。B是什么意思?只有内部类才可以定义为私有的
Which of the following statements are true? Select all valid answers.
A) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.
B) Under no circumstances can a class be defined with the private modifier
C) A inner class can be defined with the protected modifier
D) An interface cannot be instantiated
ACD
53.String数组的[]是访问相当于.访问,因此会改变值,传得是地址,但是照着地址能够改到值
What does the following program do when it is run with the command:
java Mystery Mighty Mouse
class Mystery {
   public static void main(String[] args) {
      Changer c = new Changer();
      c.method(args);
      System.out.println(args[0] + " " + args[1]);
   }
   static class Changer {
      void method(String[] s) {
         String temp = s[0];
         s[0] = s[1];
         s[1] = temp;
      }
   }
}
A) This program causes an ArrayIndexOutOfBoundsException to be thrown
B) This program runs but does not write anything to the standard output
C) This program writes "Mighty Mouse" to the standard output
D) This program writes "Mouse Mighty" to the standard output
D
54.最无厘头的选项
What can you write at the comment //A in the code below so that this program writes the word "running" to the standard output?
class RunTest implements Runnable {
   public static void main(String[] args) {
      RunTest rt = new RunTest();
      Thread t =new Thread(rt);
      //A
   }
   public void run() {
      System.out.println("running");
   }
   void go() {
      start(1);
   }
   void start(int i) {
   }
}
A) System.out.println("running");
B) rt.start();
C) rt.go();
D) rt.start(1);
A
55.浮点数要加上f.强制类型转换不可以,要显式的写为int i=(int)f;
Analyze these two consecutive lines of code:
float f = 3.2;
int i = f;
Select all valid answers.
A) this code would not compile
B) this code would compile and i would be set to 3
C) the second line could compile if it were written instead as:
   int i = (byte)f;
D) the first line could compile if it were written instead as:
   float f = 3.2F;
A
56.this不可用于静态
Analyze the following code:
class WhatHappens implements Runnable {
   public static void main(String[] args) {
      Thread t = new Thread(this);
      t.start();
   }
   public void run() {
      System.out.println("hi");
   }
}
A) This program does not compile(Cannot use this in a static context)
B) This program compiles but nothing appears in the standard output
C) This program compiles and the word "hi" appears in the standard output, once
D) This program compiles and the word "hi" appears continuously in the standard output until the user hits control-c to stop the program
A
57. final class允许继承别的类,但是不允许被继承
Analyze the following two classes.
class First {
   static int a = 3;
}
final class Second extends First {
   void method() {
      System.out.println(a);
   }
}
A) Class First compiles, but class Second does not
B) Class Second compiles, but class First does not
C) Neither class compiles
D) Both classes compile, and if method() is invoked, it writes 3 to the standard output
E) Both classes compile, but if method() is invoked, it throws an exception
D
58.注意:byte的大小范围是(-128~127),字节和字符串要添在一起的话,字节只能恰好是一位。
Which of the following are valid statements? Select all valid answers.
A) System.out.println(1+1);
B) int i= 2+'2';
C) String s= "on"+'one';
D) byte b=255;(-128~127)
AB
59. Math.ceil(); //取最接近且最大的整数
Math.floor(); //取最接近且最小的整数
Math.abs (); //取正数
What will the result be for the following block of code when it is executed?
int i = 3;
int j = 0;
float k = 3.2F;
long m = -3;
if (Math.ceil(i) < Math.floor(k))
   if (Math.abs(i) == m)
      System.out.println(i);
   else
      System.out.println(j);
else
   System.out.println(Math.abs(m) + 1);
 
A) 3
B) 0
C) -3
D) 4
E) none of these
D
60.Byte是-128到127
Which of the following statements are true?
A) A byte can represent between -128 to 127
B) A byte can represent between -127 to 128
C) A byte can represent between -256 to 256
D) A char can represent between -2x2 pow 16 2 x2 pow 16 - 1 (0~2x16-1)
A
61.注意:try后面要么有catch,要么有finally,或者都有,但是不能一个都没有
Which of the following statements about try, catch, and finally are true?
Select all valid answers.
A) A try block must always be followed by a catch block
B) A try block can be followed either by a catch block or a finally block, or both
C) A catch block must always be associated with a try block
D) A finally can never stand on its own (that is, without being associated with try block)
E) None of these are true
BCD
62.不能对非静态的进行静态引用
What will happen if you try to compile and run the following code
public class MyClass {
public static void main(String arguments[])
{
amethod(arguments);
}
public void amethod(String[] arguments)
{
System.out.println(arguments);
System.out.println(arguments[1]);
}
}
A) error Can`t make static reference to void amethod.
B) error method main not correct
C) error array must include parameter
D) amethod must be declared with String
A
63.超长了,从0开始算起
What will be printed out if this code is run with the following command line:
java myprog good morning
public class myprog{
public static void main(String argv[])
{
System.out.println(argv[2])
}
}
A) myprog
B) good
C) morning
D) Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
D
64.这道题中$似乎是可以的
Which of the following are legal identifiers?
Select all valid answers.
A) 2variable
B) variable2
C) _whatavariable
D) _3_
E) $anothervar
F) #myvar
BCD
65. Panel上的不会变
import java.awt.*;
public class X extends Frame{
public static void main(String[] args){
X x=new X();
x.pack();
x.setVisible(true);}
public X(){
setLayout(new GridLayout(2,2));
Panel p1=new Panel();
add(p1);
Button b1=new Button("One");
p1.add(b1);
Panel p2=new Panel();
add(p2);
Button b2=new Button("Two");
p2.add(b2);
Button b3=new Button("Three");
p2.add(b3);
Button b4=new Button("Four");
add(b4);
}
}
when the frame is resized,
A.all change height
B.all change width
C.Button "One" change height
D.Button "Two" change height
E.Button "Three" change width
F.Button "Four" change height and width
F
66.本题注意:1。substring(3)是指从第三位开始一直到字符串的最后一个字符
              2.Concat是指在字符串后面添加字符串。
              3.本题的迷惑性在于,foo本身其实没有被改变。
1)public class X{
2) public static void main(String[] args){
3) String foo="ABCDE";
4) foo.substring(3);
5) foo.concat("XYZ");
6) }
7) }
what is the value of foo at line 6?
ABCDE
67.
How to calculate cosine 42 degree?
A.double d=Math.cos(42);
B.double d=Math.cosine(42);
C.double d=Math.cos(Math.toRadians(42));
D.double d=Math.cos(Math.toDegrees(42));
E.double d=Math.toRadious(42);

68.还是传值传参,地址动作的问题
public class Test{
public static void main(String[] args){
StringBuffer a=new StringBufer("A");
StringBuffer b=new StringBufer("B");
operate(a,b);
System.out.pintln(a+","+b);
}
public static void operate(StringBuffer x, StringBuffer y){
x.append(y);
y=x;
}
}
what is the output?
AB,B
69.虽然foo没有初始化过,但是他获得了object的地址,所以一样能访问
1)public class Test{
2)public static void main(String[] args){
3) class Foo{
4) public int i=3;
5) }
6)Object o=(Object)new Foo();
7) Foo foo=(Foo)O;
System.out.println(foo.i);
9) }
10) }
what is result?
A.compile error at line 6
B.compile error at line 7
C.print out 3
C
70.a++和++a区别是:a++本身的值不变,a加上了1。++a本身的值加上了1,a也加上了1。
注意的是,对于这里的for循环来说,先执行循环体里的内容,然后才是最后的值修改,注意力不要被移走,上来就++。
另:这里的break tp很关键,它在跳出以后,是真正的跳出了整个循环的,不要误解为像goto那样还会被执行到。这里的tp作用在于定位跳出点,跳出点label必须在循环体结构上,且为了能够reach下一层,在这里必须是在最外侧的for前。
public class FooBar{
public static void main(String[] args){
int i=0,j=5;
4) tp: for(;;i++){
for(;;--j)
if(i>j)break tp;
}
System.out.println("i="+i+",j="+j);
}
}
what is the result?
A.i=1,j=-1 B. i=0,j=-1 C.i=1,j=4 D.i=0,j=4
E.compile error at line 4
B
71.本题注意:System.exit(0)优先级最高,早于finally被执行。而通常对于return,则是先执行finally然后才是return.
public class Foo{
public static void main(String[] args){
try{System.exit(0);}
finally{System.out.println("Finally");}
}
}
what is the result?
A.print out nothing
B.print out "Finally"
A
72.
which four types of objects can be thrown use "throws"?
A.Error
B.Event
C.Object
D.Excption
E.Throwable
F.RuntimeException
ADEF

73.java没有显式的unsigned
1)public class Test{
2) public static void main(String[] args){
3) unsigned byte b=0;
4) b--;
5)
6) }
7) }
what is the value of b at line 5?
A.-1 B.255 C.127 D.compile fail
E.compile succeeded but run error
D
74.要手工抛出异常的话,那么路径上每一级都要抛出
public class ExceptionTest{
class TestException extends Exception{}
public void runTest() throws TestException{}
public void test() /* point x */ {
runTest();
}
}
At point x, which code can be add on to make the code compile?
A.throws Exception B.catch (Exception e)
A
75.boolean默认就是false
String foo="blue";
boolean[] bar=new boolean[1];
if(bar[0]){
foo="green";
}
what is the value of foo?
A."" B.null C.blue D.green
C
76.注意o2已经被o1赋值。此时o1o2的地址相同,内容也相同
public class X{
public static void main(String args[]){
Object o1=new Object();
Object o2=o1;
if(o1.equals(o2)){
System.out.prinln("Equal");
}
}
}
what is result?
Equal
77.碰运气吧。>>相当于除以2的若干次方,<<相当于乘以2的若干次方。^异或就不用管了,二进制不会算。有右移>>>没有左移<<<,都有<<>>
 which two are equivalent?
A. 3/2
B. 3<2
C. 3*4
D. 3<<2
E. 3*2^2
F. 3<<<2
CD
78.默认为null
 int index=1;
String[] test=new String[3];
String foo=test[index];
what is the result of foo?
A. "" B.null C.throw a Exception D.not compile
B
79.看到左移赋值不要慌,其实就是传参的问题么,局部变量不用管
public class Test{
static void leftshift(int i, int j){
i<<=j;
}
public static void main(String args[]){
int i=4, j=2;
leftshift(i,j);
System.out.println(i);
}
}
what is the result?
4
80.还是传值传参,局部和全局变量的关系
public class X{
private static int a;
public static void main(String[] args){
modify(a);
System.out.println(a);
}
public static void modify(int a){
a++;
}
}
what is the result?
0

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics