- 浏览: 63931 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
brxonline:
提示不能这样写234390216 写道234390216 写道 ...
mysql导出数据为excel -
234390216:
234390216 写道不行啊,错误
提示不能这样写
mysql导出数据为excel -
234390216:
不行啊,错误
mysql导出数据为excel
1.
A.Compilation fails
B.An exception is thrown at runtime
C.An instance of Forest is Serialized
D.An instance of Forest and an instance of Tree are both serialized
2.
Which code inserted ,will allow this class to correctly seerialized and desterilize?
A.s.defaultReadObject();
B.this=s.defaultReadObject();
C.y=s.default();x=s.readInt();
D.x=s.readInt();y=s.readInt();
3.
What is the result?
A.0
B.1
C.4
D.Compilation fails
E.An exception is thrown at runtime
4.
The variable df is an object of type DateFormat that has been initialized before line 1. what is the result if this code is run on December 14,2000?
A.The value of S is 14-dic-2004
B.The value of S is Dec 14,2000
C.An exception is throw at runtime
D.Compilation fals because of an error in line 2
5.
When comparing java.io.BufferedWriter to java.io.FileWriter,which capability exist as method in only one of the two?
A.closing the stream
B.flushing the stream
C.writing to the stream
D.marking a location in the stream
E.writing a line separator the stream
6.
which two code fragments, inserted independently ,generate the output 4247?(choose two)
A.String s="123456789";
s=(s-"123").replace(1,3,"24")-"89";
B.StringBuffer s = new StringBuffer("123456789");
s.delete(0,3).replace(1,3,"24").delete(4,6);
C.StringBuffer s = new StringBuffer("123456789");
s.substring(3,6).delete(1,3).insert(1,"24");
D.StringBuffer s = new StringBuffer("123456789");
s.substring(3,6).delete(1,2).insert(1,"24");
E.StringBuffer s = new StringBuffer("123456789");
s.delete(0,3).replace(1,3).delete(2,5).insert(1,"24");
7.
Which three statements concerning the use of the java.io.Sealizable interface are true?(choose three)
A.Object from classes tha use aggregation cannot be seriablized
B.An object serialized on one JVM can be successfully desterilized on a different JVM.
C.The values in field with the Volatile modifier will NOT survive serialization and deserailization
D.The values in field with the transient modifier will NOT survive serialization and deserialization
E.It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serialization
8.
What is the result?
A.short Long
B.SHORT LONG
C.Compilation fails
D.An exception is throw at runtime
9.
d is valid,non-null Date object
df is a valid non-null DateFormat object set to the curent local
What output the current;local's country name and the appropriate version of d's date?
A.Local loc=Local.getLocal();
System.out.println(loc.getDisplayCountry());
B.Local loc=Local.getDefault();
System.out.println(loc.getDisplayCountry()+"" +df.setDateFormat(d));
C.Local loc=Local.getLocal();
System.out.println(loc.getDisplayCountry()+"" +df.setDateFormat(d));
D.Local loc=Local.getDefault();
System.out.println(loc.getDisplayCountry()+"" +df.setDateFormat(d));
10.
What is the result?
A.Compilation fails
B.An exception is thrown at runtime
C.The code executes and prints "running"
D.The code executes and prints "runningrunning"
E.The code executes and prints "runningrunningrunning"
11.
Given:
Which three are valid on line 12? (Choose three.)
A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected
Answer: ABD
12.
Given:
Which two code fragments, inserted independently at line 12, will allow
the class to compile? (Choose two.)
A. foreach(x) System.out.println(z);
B. for(int z : x) System.out.println(z);
C. while( x.hasNext()) System.out.println( x.next());
D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);
Answer: BD
13.
Given:
What is the result?
A. 2
B. 3
C. 1 2
D. 2 3
E. 1 2 3
F. Compilation fails.
G. Au exceptional is thrown at runtime.
Answer: D
14.
Given:
Under which three circumstances will the code on line 37 be executed?
(Choose three.)
A. The instance gets garbage collected.
B. The code on line 33 throws an exception.
C. The code on line 35 throws an exception.
D. The code on line 31 throws an exception.
E. The code on line 33 executes successfully.
Answer: BCE
15.
Given:
Which code, inserted at line 16, will cause a
java.lang.ClassCastException?
A. Alpha a = x;
B. Foo f= (Delta)x;
C. Foo f= (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
Answer: B
16
Given:
• d is a valid, non-null Date object
• df is a valid, non-null DateFormat object set to the
current locale
What outputs the current locales country name and the appropriate
version of d’s date?
A. Locale loc = Locale.getLocale();
System.out.println(loc.getDisplayCountry()
+ “ “+ df.format(d));
B. Locale loc = Locale.getDefault();
System.out.println(loc.getDisplayCountry()
+ “ “ + df.format(d));
C. Locale bc = Locale.getLocale();
System.out.println(loc.getDisplayCountry()
+ “ “+ df.setDateFormat(d));
D. Locale loc = Locale.getDefault();
System.out.println(loc.getDispbayCountry()
+ “ “+ df.setDateFormat(d));
Answer: B
17.
Given:
Which is true?
A. The class is fully encapsulated.
B. The code demonstrates polymorphism.
C. The ownerName variable breaks encapsulation.
D. The cardlD and limit variables break polymorphism.
E. The setCardlnformation method breaks encapsulation.
Answer: C
18.
Assume that country is set for each class.
Given:
Which two are correct? (Choose two.)
A. Yen returns correct values.
B. Euro returns correct values.
C. An exception is thrown at runtime.
D. Yen and Euro both return correct values.
E. Compilation fails because of an error at line 25.
F. Compilation fails because of an error at line 30.
Answer: BE
19.
Which Man class properly represents the relationship “Man has a best
friend who is a Dog”?
A. class Man extends Dog { }
B. class Man implements Dog { }
C. class Man { private BestFriend dog; }
D. class Man { private Dog bestFriend; }
E. class Man { private Dog<bestFriend> }
F. class Man { private BestFriend<dog> }
Answer: D
20.
Given:
Which is true?
A. The time to find the value from HashMap with a Person key depends
on the size of the map.
B. Deleting a Person key from a HashMap will delete all map entries for
all keys of type Person.
C. Inserting a second Person object into a HashSet will cause the first
Person object to be removed as a duplicate.
D. The time to determine whether a Person object is contained in a
HashSet is constant and does NOT depend on the size of the map.
Answer: A
21.Given:
foo and bar are public references available to many other threads. foo refers to a
Thread and bar is an Object. The thread foo is currently executing bar.wait().
From another thread, what provides the most reliable way to ensure that foo will
stop executing wait()?
A. foo.notify();
B. bar.notify();
C. foo.notiyAll();
D. Thread.notify();
E. bar.notifyAll();
F. Object.notify();
Answer: E
22
Given:
1. public class returnIt {
2. returnType methodA(byte x, double y){
3. return (short) x/y * 2;
4. }
5. }
What is the valid returnType for methodA in line 2?
A. int
B. byte
C. long
D. short
E. float
F. double
Answer F
注释:short类型的x,除以double类型的y,再乘int的2,所以结果是double类型的。注意第三行的强制转换,只是转换了x。
23.
1) class Super{
2) public float getNum(){return 3.0f;}
3) }
4)
5) public class Sub extends Super{
6)
7) }
which method, placed at line 6, will cause a compiler error?
A. public float getNum(){return 4.0f;}
B. public void getNum(){}
C. public void getNum(double d){}
D. public double getNum(float d){return 4.0d;}
Answer :B
注意这道题主要考的是方法的overload和override。对于overload,只有参数列表不同,才做为标准,而返回值和访问控制关键字不能做为标准,所以B错在方法名相同,但只有返回值不同,这是错的。C和D是正确的overload。对于override,则访问控制关键字只能更加公有化,异常只能是超类方法抛出的异常的子类,也可以不抛出。返回类型,参数列表必须精确匹配。所以A是正确的override。
24.
1)public class Foo{
2) public static void main(String args[]){
3) try{return;}
4) finally{ System.out.println("Finally");}
5) }
6) }
what is the result?
A. The program runs and prints nothing.
B. The program runs and prints “Finally”.
C. The code compiles, but an exception is thrown at runtime.
D. The code will not compile because the catch block is missing.
Answer:b
try......catch......finally的问题。程序中如果遇到return,则finally块先被执行,然后再执行retrun,而finally块后面的语句将不被执行。如果遇到System.exit(1),则finally块及其后的语句都不执行,整个程序退出,还执行什么呀。
25.
1) public class Test{
2) public static String output="";
3) public static void foo(int i){
4) try {
5) if(i==1){
6) throw new Exception();
7) }
8) output +="1";
9) }
10) catch(Exception e){
11) output+="2";
12) return;
13) }
14) finally{
15) output+="3";
16) }
17) output+="4";
18) }
19) public static void main(String args[]){
20) foo(0);
21) foo(1);
22)
23) }
24) }
what is the value of output at line 22?
Asnwer:13423
执行第一个foo(0)时,执行第8条语句,output=1,然后执行语句15,output=13,然后是17条,output=134,因为是static类型的变量,所以任何对其值的修改都有效。执行第二条foo(1),先执行语句5,结果抛出异常,转到catch块,output=1342,finally任何情况下都执行,所以output=13423,然后return跳出方法体,所以output=13423
26.
1)public class IfElse{
2)public static void main(String args[]){
3)if(odd(5))
4)System.out.println("odd");
5)else
6)System.out.println("even");
7)}
8)public static int odd(int x){return x%2;}
9)}
what is output?
Answer: 编译错误。
if中的判断条件的结果必须是boolean类型的。注意这里说的是结果.
27.
1)class ExceptionTest{
2)public static void main(String args[]){
3)try{
4)methodA();
5)}catch(IOException e){
6)System.out.println("caught IOException");
7)}catch(Exception e){
8)System.out.println("caught Exception");
9) }
10) }
11)}
If methodA() throws a IOException, what is the result?
Answer: caught IOException
如果methodA()抛出IOExecption,被语句6捕获,输出caught IOException,然后呢??然后就结束了呗。
28.
1)int i=1,j=10;
2)do{
3) if(i++>--j) continue;
4)}while(i<5);
After Execution, what are the value for i and j?
A. i=6 j=5
B. i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
Answer: d
程序一直循环,直到i=4,j=6时,执行完语句3后,i会++,这时i就等于了5,continue后就不能再循环了,所以选D。
29.
1)public class X{
2) public Object m(){
3) Object o=new Float(3.14F);
4) Object[] oa=new Object[1];
5) oa[0]=o;
6) o=null;
7) oa[0]=null;
8) System.out.println(oa[0]);
9) }
10) }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A.After line 4
B. After line 5
C.After line 6
D.After line 7
E.After line 9(that is,as the method returns)
Answer: d
当执行第6行后,仍然有对象指向o,所以o不能满足条件,当第7条语句被执行后,就再也没有对象指向o了,所以选D。
30.
1) interface Foo{
2) int k=0;
3) }
4) public class Test implements Foo{
5) public static void main(String args[]){
6) int i;
7) Test test =new Test();
i=test.k;
9) i=Test.k;
10) i=Foo.k;
11) }
12) }
What is the result?
A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.
Answer: A
编译通过,通过测试的
31.
what is reserved words in java?
A. run
B. default
C. implement
D. import
Answer: b,D
32.
1)public class Test{
2) public static void main(String[] args){
3) String foo=args[1];
4) Sring bar=args[2];
5) String baz=args[3];
6) }
7) }
java Test Red Green Blue
what is the value of baz?
A. baz has value of ""
B. baz has value of null
C. baz has value of "Red"
D. baz has value of "Blue"
E. baz has value of "Green"
F. the code does not compile
G. the program throw an exception
Answer: G
当执行java Test Red Green Blue时,数组args只有[0][1][2],运行时ArrayIndexOutOfBoundsException这个异常会被抛出,数组越界。
33.
int index=1;
int foo[]=new int[3];
int bar=foo[index];
int baz=bar+index;
what is the result?
A. baz has a value of 0
B. baz has value of 1
C. baz has value of 2
D. an exception is thrown
E. the code will not compile
Answer: b
数组初始化后默认值是0,所以baz=0+1=1
34.
which three are valid declaraction of a float?
A. float foo=-1;
B. float foo=1.0;
C. float foo=42e1;
D. float foo=2.02f;
E. float foo=3.03d;
F. float foo=0x0123;
Answer: A,D,F
其它的系统都会认为是double类型,所以出错。说一下A和C的区别吧,-1系统会认为是一个int类型,把int类型再赋给float类型的foo,当然没错了,可C就不同啦,42e1是int类型吗??
35.
1)public class Foo{
2) public static void main(String args[]){
3) String s;
4) System.out.println("s="+s);
5) }
6) }
what is the result?
A. The code compiles and “s=” is printed.
B. The code compiles and “s=null” is printed.
C. The code does not compile because string s is not initialized.
D. The code does not compile because string s cannot be referenced.
E. The code compiles, but a NullPointerException is thrown when toString is called.
Answer:C
只有实例变量系统才给予自动赋默认值的这种待遇
36.
1) public class Test{
2) public static void main(String args[]){
3) int i=oxFFFFFFF1;
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
算一算就知道了。
37.
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
==两边类型不同不相等。所以A和C不等。equals只能用于引用类型,不能用于基本类型,所以D不对,而且两边类型不兼容的话,即使对象的内容一样,也不相等,所以E和F不对。
38.
1)public class Test{
2) public static void add3(Integer i){
3) int val=i.intValue();
4) val+=3;
5) i=new Integer(val);
6) }
7) public static void main(String args[]){
8) Integer i=new Integer(0);
9) add3(i);
10) System.out.println(i.intValue());
11) }
12)}
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
在第五行里,程序又操作了New,重新分配了内存空间。所以此i非彼i啦。
39.
1)public class Test{
2) public static void main(String[] args){
3) System.out.println(6^3);
4) }
5) }
what is output?
Answer: 5算呗。
40.
1) public class Test{
2) public static void stringReplace(String text){
3) text=text.replace('j','l');
4) }
5) public static void bufferReplace(StringBuffer text){
6) text=text.append("c");
7) }
8) public static void main(String args[]){
9) String textString=new String("java");
10) StringBuffer textBuffer=new StringBuffer("java");
11) StringReplace(textString);
12) bufferReplace(textBuffer);
13) System.out.println(textString+textBuffer);
14) }
15) }
what is the output?
Answer: javajavac
textString是String类型的,具有不变性,语句3其实是创建了一个新的字符串,而不是修改原来的textString,而对于StringBuffer类型的对象,则所有修改都是实在的。所以在语句6中textBuffer变成了javac,所以输出为javajavac。
package main; import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Forest implements Serializable { private Tree tree = new Tree(); /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Forest f = new Forest(); try { FileOutputStream fs = new FileOutputStream("Forest.ser"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(f); os.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class Tree { }
A.Compilation fails
B.An exception is thrown at runtime
C.An instance of Forest is Serialized
D.An instance of Forest and an instance of Tree are both serialized
2.
package main; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Foo implements Serializable { public int x,y; public Foo(int x,int y) { this.x=x; this.y=y; } private void writeObject(ObjectOutputStream s) throws IOException{ s.writeInt(x); s.writeInt(y); } private void readObject(ObjectInputStream s) throws IOException,ClassNotFoundException{ //insert code here } }
Which code inserted ,will allow this class to correctly seerialized and desterilize?
A.s.defaultReadObject();
B.this=s.defaultReadObject();
C.y=s.default();x=s.readInt();
D.x=s.readInt();y=s.readInt();
3.
String test="This is a test"; String [] tokens = test.split("\s"); System.out.println(tokens.length);
What is the result?
A.0
B.1
C.4
D.Compilation fails
E.An exception is thrown at runtime
4.
Date date = new Date(); df.setLocale(Local.Italy); String s = df.Format(date);
The variable df is an object of type DateFormat that has been initialized before line 1. what is the result if this code is run on December 14,2000?
A.The value of S is 14-dic-2004
B.The value of S is Dec 14,2000
C.An exception is throw at runtime
D.Compilation fals because of an error in line 2
5.
When comparing java.io.BufferedWriter to java.io.FileWriter,which capability exist as method in only one of the two?
A.closing the stream
B.flushing the stream
C.writing to the stream
D.marking a location in the stream
E.writing a line separator the stream
6.
public class Certkiller3 { public static void main(String [] args) //insert code here System.out.println(s); }
which two code fragments, inserted independently ,generate the output 4247?(choose two)
A.String s="123456789";
s=(s-"123").replace(1,3,"24")-"89";
B.StringBuffer s = new StringBuffer("123456789");
s.delete(0,3).replace(1,3,"24").delete(4,6);
C.StringBuffer s = new StringBuffer("123456789");
s.substring(3,6).delete(1,3).insert(1,"24");
D.StringBuffer s = new StringBuffer("123456789");
s.substring(3,6).delete(1,2).insert(1,"24");
E.StringBuffer s = new StringBuffer("123456789");
s.delete(0,3).replace(1,3).delete(2,5).insert(1,"24");
7.
Which three statements concerning the use of the java.io.Sealizable interface are true?(choose three)
A.Object from classes tha use aggregation cannot be seriablized
B.An object serialized on one JVM can be successfully desterilized on a different JVM.
C.The values in field with the Volatile modifier will NOT survive serialization and deserailization
D.The values in field with the transient modifier will NOT survive serialization and deserialization
E.It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serialization
8.
public class Certkiller { public static void go(short n) { System.out.println("short"); } public static void go(short n) { System.out.println("SHORT"); } public static void go(Long n) { System.out.println("LONG"); } public static void main(String []args) { Short y=6; int z=7; go(y); go(z); } }
What is the result?
A.short Long
B.SHORT LONG
C.Compilation fails
D.An exception is throw at runtime
9.
d is valid,non-null Date object
df is a valid non-null DateFormat object set to the curent local
What output the current;local's country name and the appropriate version of d's date?
A.Local loc=Local.getLocal();
System.out.println(loc.getDisplayCountry());
B.Local loc=Local.getDefault();
System.out.println(loc.getDisplayCountry()+"" +df.setDateFormat(d));
C.Local loc=Local.getLocal();
System.out.println(loc.getDisplayCountry()+"" +df.setDateFormat(d));
D.Local loc=Local.getDefault();
System.out.println(loc.getDisplayCountry()+"" +df.setDateFormat(d));
10.
public class Cerkiller3 implements Runnable{ public void run() { System.out.print("running"); } public static void main(String[] args) { Thread t = new Thread(new Cerkiller3()); t.run(); t.run(); t.start(); } }
What is the result?
A.Compilation fails
B.An exception is thrown at runtime
C.The code executes and prints "running"
D.The code executes and prints "runningrunning"
E.The code executes and prints "runningrunningrunning"
11.
Given:
11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. }
Which three are valid on line 12? (Choose three.)
A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected
Answer: ABD
12.
Given:
10. public class Bar { 11.static void foo(int...x) { 12. // insert code here 13. } 14. }
Which two code fragments, inserted independently at line 12, will allow
the class to compile? (Choose two.)
A. foreach(x) System.out.println(z);
B. for(int z : x) System.out.println(z);
C. while( x.hasNext()) System.out.println( x.next());
D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);
Answer: BD
13.
Given:
11. public class Test { 12. public static void main(String [] args) { 13. int x =5; 14. boolean b1 = true; 15. boolean b2 = false; 16. 17.if((x==4) && !b2) 18. System.out.print(”l “); 19. System.out.print(”2 “); 20. if ((b2 = true) && b1) 21. System.out.print(”3 “); 22. } 23. }
What is the result?
A. 2
B. 3
C. 1 2
D. 2 3
E. 1 2 3
F. Compilation fails.
G. Au exceptional is thrown at runtime.
Answer: D
14.
Given:
31. // some code here 32. try { 33. // some code here 34. } catch (SomeException se) { 35. // some code here 36. } finally { 37. // some code here 38. }
Under which three circumstances will the code on line 37 be executed?
(Choose three.)
A. The instance gets garbage collected.
B. The code on line 33 throws an exception.
C. The code on line 35 throws an exception.
D. The code on line 31 throws an exception.
E. The code on line 33 executes successfully.
Answer: BCE
15.
Given:
10. interface Foo {} 11. class Alpha implements Foo { } 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args) { 15. Beta x = new Beta(); 16. // insert code here 17. } 18. }
Which code, inserted at line 16, will cause a
java.lang.ClassCastException?
A. Alpha a = x;
B. Foo f= (Delta)x;
C. Foo f= (Alpha)x;
D. Beta b = (Beta)(Alpha)x;
Answer: B
16
Given:
• d is a valid, non-null Date object
• df is a valid, non-null DateFormat object set to the
current locale
What outputs the current locales country name and the appropriate
version of d’s date?
A. Locale loc = Locale.getLocale();
System.out.println(loc.getDisplayCountry()
+ “ “+ df.format(d));
B. Locale loc = Locale.getDefault();
System.out.println(loc.getDisplayCountry()
+ “ “ + df.format(d));
C. Locale bc = Locale.getLocale();
System.out.println(loc.getDisplayCountry()
+ “ “+ df.setDateFormat(d));
D. Locale loc = Locale.getDefault();
System.out.println(loc.getDispbayCountry()
+ “ “+ df.setDateFormat(d));
Answer: B
17.
Given:
20. public class CreditCard { 21. 22. private String cardlD; 23. private Integer limit; 24. public String ownerName; 25. 26. public void setCardlnformation(String cardlD, 27. String ownerName, 28. Integer limit) { 29. this.cardlD = cardlD; 30. this.ownerName = ownerName; 31. this.limit = limit; 32. } 33. }
Which is true?
A. The class is fully encapsulated.
B. The code demonstrates polymorphism.
C. The ownerName variable breaks encapsulation.
D. The cardlD and limit variables break polymorphism.
E. The setCardlnformation method breaks encapsulation.
Answer: C
18.
Assume that country is set for each class.
Given:
10. public class Money { 11. private String country, name; 12. public getCountry() { return country; } 13.} and: 24. class Yen extends Money { 25. public String getCountry() { return super.country; } 26. } 27. 28. class Euro extends Money { 29. public String getCountry(String timeZone) { 30. return super.getCountry(); 31. } 32. }
Which two are correct? (Choose two.)
A. Yen returns correct values.
B. Euro returns correct values.
C. An exception is thrown at runtime.
D. Yen and Euro both return correct values.
E. Compilation fails because of an error at line 25.
F. Compilation fails because of an error at line 30.
Answer: BE
19.
Which Man class properly represents the relationship “Man has a best
friend who is a Dog”?
A. class Man extends Dog { }
B. class Man implements Dog { }
C. class Man { private BestFriend dog; }
D. class Man { private Dog bestFriend; }
E. class Man { private Dog<bestFriend> }
F. class Man { private BestFriend<dog> }
Answer: D
20.
Given:
11. public class Person { 12. private name; 13. public Person(String name) { 14. this.name = name; 15. } 16. public int hashCode() { 17. return 420; 18. } 19. }
Which is true?
A. The time to find the value from HashMap with a Person key depends
on the size of the map.
B. Deleting a Person key from a HashMap will delete all map entries for
all keys of type Person.
C. Inserting a second Person object into a HashSet will cause the first
Person object to be removed as a duplicate.
D. The time to determine whether a Person object is contained in a
HashSet is constant and does NOT depend on the size of the map.
Answer: A
21.Given:
foo and bar are public references available to many other threads. foo refers to a
Thread and bar is an Object. The thread foo is currently executing bar.wait().
From another thread, what provides the most reliable way to ensure that foo will
stop executing wait()?
A. foo.notify();
B. bar.notify();
C. foo.notiyAll();
D. Thread.notify();
E. bar.notifyAll();
F. Object.notify();
Answer: E
22
Given:
1. public class returnIt {
2. returnType methodA(byte x, double y){
3. return (short) x/y * 2;
4. }
5. }
What is the valid returnType for methodA in line 2?
A. int
B. byte
C. long
D. short
E. float
F. double
Answer F
注释:short类型的x,除以double类型的y,再乘int的2,所以结果是double类型的。注意第三行的强制转换,只是转换了x。
23.
1) class Super{
2) public float getNum(){return 3.0f;}
3) }
4)
5) public class Sub extends Super{
6)
7) }
which method, placed at line 6, will cause a compiler error?
A. public float getNum(){return 4.0f;}
B. public void getNum(){}
C. public void getNum(double d){}
D. public double getNum(float d){return 4.0d;}
Answer :B
注意这道题主要考的是方法的overload和override。对于overload,只有参数列表不同,才做为标准,而返回值和访问控制关键字不能做为标准,所以B错在方法名相同,但只有返回值不同,这是错的。C和D是正确的overload。对于override,则访问控制关键字只能更加公有化,异常只能是超类方法抛出的异常的子类,也可以不抛出。返回类型,参数列表必须精确匹配。所以A是正确的override。
24.
1)public class Foo{
2) public static void main(String args[]){
3) try{return;}
4) finally{ System.out.println("Finally");}
5) }
6) }
what is the result?
A. The program runs and prints nothing.
B. The program runs and prints “Finally”.
C. The code compiles, but an exception is thrown at runtime.
D. The code will not compile because the catch block is missing.
Answer:b
try......catch......finally的问题。程序中如果遇到return,则finally块先被执行,然后再执行retrun,而finally块后面的语句将不被执行。如果遇到System.exit(1),则finally块及其后的语句都不执行,整个程序退出,还执行什么呀。
25.
1) public class Test{
2) public static String output="";
3) public static void foo(int i){
4) try {
5) if(i==1){
6) throw new Exception();
7) }
8) output +="1";
9) }
10) catch(Exception e){
11) output+="2";
12) return;
13) }
14) finally{
15) output+="3";
16) }
17) output+="4";
18) }
19) public static void main(String args[]){
20) foo(0);
21) foo(1);
22)
23) }
24) }
what is the value of output at line 22?
Asnwer:13423
执行第一个foo(0)时,执行第8条语句,output=1,然后执行语句15,output=13,然后是17条,output=134,因为是static类型的变量,所以任何对其值的修改都有效。执行第二条foo(1),先执行语句5,结果抛出异常,转到catch块,output=1342,finally任何情况下都执行,所以output=13423,然后return跳出方法体,所以output=13423
26.
1)public class IfElse{
2)public static void main(String args[]){
3)if(odd(5))
4)System.out.println("odd");
5)else
6)System.out.println("even");
7)}
8)public static int odd(int x){return x%2;}
9)}
what is output?
Answer: 编译错误。
if中的判断条件的结果必须是boolean类型的。注意这里说的是结果.
27.
1)class ExceptionTest{
2)public static void main(String args[]){
3)try{
4)methodA();
5)}catch(IOException e){
6)System.out.println("caught IOException");
7)}catch(Exception e){
8)System.out.println("caught Exception");
9) }
10) }
11)}
If methodA() throws a IOException, what is the result?
Answer: caught IOException
如果methodA()抛出IOExecption,被语句6捕获,输出caught IOException,然后呢??然后就结束了呗。
28.
1)int i=1,j=10;
2)do{
3) if(i++>--j) continue;
4)}while(i<5);
After Execution, what are the value for i and j?
A. i=6 j=5
B. i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
Answer: d
程序一直循环,直到i=4,j=6时,执行完语句3后,i会++,这时i就等于了5,continue后就不能再循环了,所以选D。
29.
1)public class X{
2) public Object m(){
3) Object o=new Float(3.14F);
4) Object[] oa=new Object[1];
5) oa[0]=o;
6) o=null;
7) oa[0]=null;
8) System.out.println(oa[0]);
9) }
10) }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A.After line 4
B. After line 5
C.After line 6
D.After line 7
E.After line 9(that is,as the method returns)
Answer: d
当执行第6行后,仍然有对象指向o,所以o不能满足条件,当第7条语句被执行后,就再也没有对象指向o了,所以选D。
30.
1) interface Foo{
2) int k=0;
3) }
4) public class Test implements Foo{
5) public static void main(String args[]){
6) int i;
7) Test test =new Test();
i=test.k;
9) i=Test.k;
10) i=Foo.k;
11) }
12) }
What is the result?
A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.
Answer: A
编译通过,通过测试的
31.
what is reserved words in java?
A. run
B. default
C. implement
D. import
Answer: b,D
32.
1)public class Test{
2) public static void main(String[] args){
3) String foo=args[1];
4) Sring bar=args[2];
5) String baz=args[3];
6) }
7) }
java Test Red Green Blue
what is the value of baz?
A. baz has value of ""
B. baz has value of null
C. baz has value of "Red"
D. baz has value of "Blue"
E. baz has value of "Green"
F. the code does not compile
G. the program throw an exception
Answer: G
当执行java Test Red Green Blue时,数组args只有[0][1][2],运行时ArrayIndexOutOfBoundsException这个异常会被抛出,数组越界。
33.
int index=1;
int foo[]=new int[3];
int bar=foo[index];
int baz=bar+index;
what is the result?
A. baz has a value of 0
B. baz has value of 1
C. baz has value of 2
D. an exception is thrown
E. the code will not compile
Answer: b
数组初始化后默认值是0,所以baz=0+1=1
34.
which three are valid declaraction of a float?
A. float foo=-1;
B. float foo=1.0;
C. float foo=42e1;
D. float foo=2.02f;
E. float foo=3.03d;
F. float foo=0x0123;
Answer: A,D,F
其它的系统都会认为是double类型,所以出错。说一下A和C的区别吧,-1系统会认为是一个int类型,把int类型再赋给float类型的foo,当然没错了,可C就不同啦,42e1是int类型吗??
35.
1)public class Foo{
2) public static void main(String args[]){
3) String s;
4) System.out.println("s="+s);
5) }
6) }
what is the result?
A. The code compiles and “s=” is printed.
B. The code compiles and “s=null” is printed.
C. The code does not compile because string s is not initialized.
D. The code does not compile because string s cannot be referenced.
E. The code compiles, but a NullPointerException is thrown when toString is called.
Answer:C
只有实例变量系统才给予自动赋默认值的这种待遇
36.
1) public class Test{
2) public static void main(String args[]){
3) int i=oxFFFFFFF1;
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
算一算就知道了。
37.
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
==两边类型不同不相等。所以A和C不等。equals只能用于引用类型,不能用于基本类型,所以D不对,而且两边类型不兼容的话,即使对象的内容一样,也不相等,所以E和F不对。
38.
1)public class Test{
2) public static void add3(Integer i){
3) int val=i.intValue();
4) val+=3;
5) i=new Integer(val);
6) }
7) public static void main(String args[]){
8) Integer i=new Integer(0);
9) add3(i);
10) System.out.println(i.intValue());
11) }
12)}
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
在第五行里,程序又操作了New,重新分配了内存空间。所以此i非彼i啦。
39.
1)public class Test{
2) public static void main(String[] args){
3) System.out.println(6^3);
4) }
5) }
what is output?
Answer: 5算呗。
40.
1) public class Test{
2) public static void stringReplace(String text){
3) text=text.replace('j','l');
4) }
5) public static void bufferReplace(StringBuffer text){
6) text=text.append("c");
7) }
8) public static void main(String args[]){
9) String textString=new String("java");
10) StringBuffer textBuffer=new StringBuffer("java");
11) StringReplace(textString);
12) bufferReplace(textBuffer);
13) System.out.println(textString+textBuffer);
14) }
15) }
what is the output?
Answer: javajavac
textString是String类型的,具有不变性,语句3其实是创建了一个新的字符串,而不是修改原来的textString,而对于StringBuffer类型的对象,则所有修改都是实在的。所以在语句6中textBuffer变成了javac,所以输出为javajavac。
相关推荐
在六年级数学的学习中,每周一题精选是一个非常好的练习方式,可以帮助学生巩固和提升数学技能。这份"六年级数学上册每周一题精选.doc"文档显然聚焦于数学问题的解答和解析,尤其针对合数这一关键概念进行了深入探讨...
每周设置专门的笔算训练,例如每周十题,可以帮助学生巩固和提升这一技能,减少因粗心而导致的错误。 简算的意识培养是提升计算灵活性的重要途径。教师需要引导学生理解和掌握加法和乘法的交换律、结合律以及分配律...
培养问题意识是必要的,例如通过《现场管理人员每周十题》的方式,主动发现问题并解决问题,而不是将问题推给上级。 当设备故障、员工冲突或紧急插单等突发情况发生时,基层干部应具备快速响应和妥善处理的能力。...
【标题】:“六年级数学上册每周一题7精选.doc”文档主要涵盖了小学六年级上学期的数学问题,其中一个问题涉及到寻找最小的三位数。这个问题旨在帮助学生理解数位值的概念,以及在进行乘法运算时进位的原则。 ...
问题意识的培养是提高管理水平的关键,管理者要时刻警惕【无问题=有问题】的现象,通过【现场管理人员每周十题】等活动,主动发现和解决问题。面对问题,不应简单地将责任推给上级,而是应用【解决问题的工作单】...
此外,通过《现场管理人员每周十题》等活动,培养问题意识,鼓励员工发现并解决问题,而不是回避问题。 在应对日常工作中可能出现的各种挑战时,如设备故障、员工冲突、紧急插单等,基层干部需具备快速反应和妥善...
标题中的“五年级数学上册每周一题17精选.doc”表明这是一份针对五年级学生设计的数学练习集,每周一题旨在让学生定期巩固和提高数学技能。这份文档可能是教师或家长为孩子准备的学习资源,旨在提升孩子的数学思维...
标题中的“五年级数学上册每周一题14精选”表明这是一个针对五年级学生的数学练习题目集,重点在于提升学生解决数学问题的能力。这道第十三周的问题涉及到组合与排列的知识,具体是关于如何将一定数量的物品进行不...
9. 函数图像分析:第十题通过函数图像分析时间和速度的关系,考察理解函数图像和实际问题结合的能力。 10. 全等三角形的判定:第十一题要求选出不能判定两三角形全等的条件组合,涉及全等三角形的判定定理。 11. 等...
18. **代数表达式的化简与求值**:第十九题和第二十题是代数计算题,需要先化简代数式,然后选取合适的数值代入求解。 19. **最短路径问题**:第二十一题涉及几何中的最短路径问题,通常利用平面几何中的定理来求解...
第二十题是椭圆的标准方程和几何性质,根据给定条件求解椭圆的参数。 这些题目综合测试了学生的数学基础理论、逻辑推理、实际应用和解决问题的能力。解答这些问题需要对高中数学的多个核心概念有深入理解和熟练应用...
10. 第十题通过平均数找出特定位置上的数值。 11. 第十一题是线性方程的解法,求解第二组数的数量。 12. 第十二题分析了前后两次平均分的变化,找出单次得分的差异。 13. 第十三题是周期性事件的频率计算,求每周去...
10. **介词 of + 动名词**:第十题 "She was afraid __________ the dog in case it became dangerous." "be afraid of doing sth." 表示害怕做某事。 11. **mean 的用法**:第十一题 "The bad weather meant______...
【七下数学每周一练精选】的文档涵盖了初中一年级下学期的数学练习题目,主要涉及三角形的相关知识。以下是对这些题目中知识点的详细解析: 1. 选择题: - 第1题考察三角形的存在条件,根据三角形任意两边之和大于...
以上是七下数学第十七周每周一练中涉及的主要知识点,包括轴对称图形、几何图形性质、等腰三角形、镜面反射、时间读取、最短路径问题、动量反弹、三角形的内角和外角、几何证明等。这些知识点是初中数学学习的重要...
例如,第六题询问的是交通方式,第七题询问的是当前正在进行的活动,第八题可能涉及频率的问答,第九题可能是关于日期或特殊事件的问题,第十题则是对人物特征或来源的描述。这部分测试了学生对日常英语对话的理解和...
10. 第十题涉及到上下山的速度计算。速度等于路程除以时间。 11. 第十一题是求两个数的倍数关系,通过除法运算得出答案。 12. 第十二题是长方形面积和长的关系,长=面积/宽。 13. 第十三题运用除法计算出售草皮的...
5. 课程分周安排:文档中提及“第一门课Week1”和“第四门课Week3”,这表明课程可能是按照每周的单元来组织的。这样的安排便于学习者按照教学进度分阶段学习和复习,保证了学习的连贯性和系统性。 6. 题目中的图片...
以上是对七年级数学下册第十四周每周一练第五章三角形精选内容的详细解析,涵盖了三角形的基本概念、性质、全等三角形的判定、作图技巧以及实际问题的解决方法。通过这些习题,学生可以深入理解和掌握三角形的相关...
这份文档似乎是一份针对一年级学生的数学练习题及其解答,旨在帮助学生巩固和提高他们在数学方面的能力。下面将详细解释其中涉及的重要知识点。 ### 数学基础知识 #### 一、数字与数的概念 - **比大小的概念**:...