标题: 每日五题__(1) [打印本页] 作者: fso918 时间: 2011-9-26 11:30 标题: 每日五题__(1) 打算每天发5道题,和大家学习交流,也鞭策自己,希望大家支持。
Q:1
public class Test{
public static void main(String args[]){
class Foo{
public int i = 3;
}
Object o = (Object)new Foo();
Foo foo = (Foo)o;
System.out.println("i="+foo.i);
}
}
what is the result?
A i=3;
B Conpilation fails;
C A ClassCastException is thrown at line 6;
D ---------------------------------------- at line 7;
Q2
Which two cause a compiler error?(choose two)
A float[] = new float(3).
B float f2[] = new float[];
C foat[] f1 = new float[3];
D float f3[] = new float[3];
E float f5[] = { 1.0f;2.0f;2.0f};
F float f4[] = new float float[]{ 1.0f , 2.0f, 3.0f};
Q3
int i =1,j=10;
do{
if(i++>--j) {
continue;
}
}
while (i < 5);
System.out.println("i="+i+"and j="+j);
what is the result?
A i=6 and j=5
B i=5 and j=5
C i=5 and j=6
D i=6 and j=6
Q4
Given
1 class Test{
2 private Demo d;
3 void start(){
4 d = new Demo();
5 this.takeDemo(d);
6 }
7
8 void takeDemo(Demo demo){
9 demo = null;
10 demo = new Demo();
11 }
12 }
What id the Demo object,created on line 3,eligibe for garbage colletion?
A After line 5;
B After line 9;
C After the start() method completes.
D When the takeDemo() method completes.
E When the instance running this code id made eligible for garbage coletion.
Q6
Which statement id true?
A Memory is reclaimed by calling Runtime.gc().
B Objects are not collected if they accessible fron live threads.
C Objects that have finalize() methods are never garbage collected.
D Objects that have finalize() methods always have finalize() methods called before the propram ends.
E An OutOfMemory error id only thrown if a singe block of memory connot be found that is large
enough for a particular requirement.
[ 本帖最后由 fso918 于 2011-09-27 11:12 编辑 ]作者: 匿名 时间: 2011-9-26 11:51
answer:
1 A 2 A,B 3 C 4 E 6 B作者: 匿名 时间: 2011-9-27 10:44
第二题我怎么看每个选项都有错误呢
第四题哪有E选项啊
可以用你的题学学英语 呵呵 咱英语差得很,楼主什么时候发个中文版的,我好对照一下:lol作者: 匿名 时间: 2011-9-27 11:27
发帖的时候没有认真核对,很对不起
第二题:A float是基本数据类型,不能new一个对象,并且只能把一个数组对象赋值给数组。
B 用new生成数组时,必须在类型后面跟上[],并且中括号里必须要有int值。
C java里推荐和规范建立数组的方式。
D C语言和C++里的定义数组方法,java也支持。
E 建立数组的快捷方式,数组被直接赋初始值,数组长度为值的数量。
F 没人会这么用的,但确实能行。我认为应该是建立多维数组,在维数为 1 时的特殊情况。因为多维数组的最上层数组在建立时可以不指定大小。