上午刚考完scjp(2002.4.25)过了84,挺美。总体感觉大部分题都挺熟,差不多有1/3原题,可能sun的题库不大,这下美了我们这些善于考试的中国人。
平常作模拟题差不多一个小时完,今天用了100分钟,做的特小心,怕掉井里,对不起我那几两银子。
下面回忆一下题,记得不多,有几道算几道,希望能给后面的人提个醒儿。
1> int i=0,j=10;
top: for(;;)
{ i++;
for(;;)
{ if(i>–j) break top;}
}
问你最后i,j是几。(注意:i就变一次)
2> class test
{
public void main(string argc[])
{
system.out.println("hello");
}
}
问你输出什么。(抛出错误)
3> 大概是这样
说int a=4,j=1;
switch(a)
case 2:j++;
case 4: j++;
case 1: j++;
default j++;
system.out.println(a+j);是多少。
4> class foo
{
public static void main(string argc[])
try{
return( system.exit());
}
finally{ system.out.pringln("finally");
}输出什么。不输出 这是第一题
5> string s="blue";
string s1=s;
string s="red";
system.out.println(s1);
6> string s="blue";
boolean[] bl=new boolean[1];
if (b1[0])
s="green";
问你s最后是什么
7> 硬盘当前目录有一个文件"a.txt",里面有一些垃圾
outputstream o = new fileoutputstream(new file("a.txt"));
然后发生了什么?a.txt变成了0字节
8> string[] a=new string[3];
int i=1;
a[i]是什么?(null)
9> 单选
a.gridbaglayout里面一个格子的component either随frame改变大小or保持perfect size在
格子中间。
b.frame里面borderlayout的north位置是菜单的好位置
c.不记得了
d.不记得了
注意 a和b都是错的,我选c
10> class a{
integer u(){return new integer(4);}
}
class b extends a{
long u(){return new long(8);}
public static void main(string[] args){
..
}
}
问结果,结果是编译不通,override方法的返回值必须一样
11> innter class can be static
anonymous inner class can be public
………………………. static
………………………. privated
………………………. protected
这题为a
12> …
nsigned byte i =20;
…
编译错误
13> 问char的范围(不说也会吧)
14> class a{
public string tostring(){
return "4"
}
}
class b extends a{
public string tostring(){
return super.tostring()+"3";
}
public static void main(string[] args){
system.out.println(new b());
}
}
问输出,为"43"
这题考过多次了。
15>java test red green blue
class test{
pubic static void main(string[] args){
string k1 = args[0];
string k2 = args[1];
string k3 = args[2];
}
}
问你k3是什么。blue,可能出题人喜欢蓝色,好几道题答案是这个
16> class a implements runnable{
public void run(){
system.out.println("blue");
}
}
问你如何在一个new thread 中打印出blue
给你一些答案,你一眼就知识几,特一贼
17> 考randomaccessfile的构造器,问你如何向一个文件尾添加“<end>"
a. …randomaccessfile(xxx,"a")
b. …………………..,"r")
c. …………………..,"rw")
d. …………………..,"w")
我选c.当时不知对不对(当时也想d了,因为是单选,看c比较熟)
18> 一个frame,
程序里面用了setlayout(new borderlayout());//这是蒙你的,下边的panel是flow
panel p = new panel();
button b1 = new button();
p.add(b1);
add(p,北边);
button b2 = new button();
add(b2,南边);
….
问你两个button是有相同的高还是宽,frame改变大小时谁的宽不变(高,b1)
19> java.io.printstream p = new java.io.printstream(
new java.io.inputstreamreader(system.out)
)
问你有不用加import xxx
thread的题考的还是那几个,以前我看过有个网友的回忆,我这次和他的一样,其实上面的题大部分也都一样,认真看呦,你没准也会碰到。下面我把那个网友的回忆的占下来。
class a implements runnable{
private int x;
private int y;
public void run(){
for(;;){
x++;
y++;
system.out.println(" x="+x+" y="+y);
system.out.println(当前thread的名字);
}
}
}
class b{
public static void main(string[] args){
a aa = new a();
new thread(aa).start();
new thread(aa).start();
}
}
给几个选项,问你运行结果
非常碰巧,上面这道题改了一下又出现在我的考题里面
//前面一样
synchronized(this){
x++;
y++;
}
system.out.println…//后面一样
同样是给你几个选项,问运行结果
这个是同步的,上面那个有可能输出x!=y的结果,这个就不会了
大家要注意5,6都只有一个aa,也就是不会出现相同的x或y.
还有一个很经典的thread题,也是真题,
thread1
synchronized(a){
synchronized(b){
}
}
thread2
synchronized(b){synchronized(a){
}
}
都start();问结果,结果是 可能deadlock,就是大家很常见的那道题
a,b是stringbuffer();thread1,2是用
new thread(){
public void run(){
//….
}
}.start();
方式定义
一字不变 (我这题可能错了,当时我记得论坛里说过的,答案忘了,我肯定下次还有这个)
对了还有,前天还在论坛里说呢
which two declaretions provent 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(){}
答案现在我也不敢定,有人说(书上)是a,d.可一个是static 一个是non-static呀
我在机器试着a,d不成。我说是c,d.只要是c在前,d在后就成(试过)
还有:问鼠标移动要实现那个接口(明白人知道我再说什么吧),key pressed要那个接口,俩题。
垃圾回收问你第几行那个(就是好多模拟是都有的那个,在第7行后)
有一个考数学函数的题忘了,答案是int a=(int)round(double b)
还有hashtable继承的那个接口。(map)
问你有这种形式的什么key-values,选两个(map,sortedmap)
提问:能让进程停止的选两个
a.wait();
b.notify();
c.notifyall();
d.退出synchronized black
e.call setpriority();
这题我可能错了(a,d)
得到父目录的方法是什么,自己找吧。
还有一个,最后一个了只能回忆这么多了(内存有限)。
class a
{
class inerexception extends exception{}
void trytest() throws inerexception{};
void test() //xxxxxxxx
{
trytest();
}
}
xxxxxx有什么代替
a.throws exception
b.catch(….)
c.throw inerexception
d.throws inerexception
e.好像还有一catch的
答案 a
总之,上面这些题在mock test中大多有涉及,我发现网上的朋友真无私,提供那么多不用银子的mock test.我太感动了流泪了:)..。从对java一点不会到今天考完,仨月,长了点(我笨),可能有人不用一月就搞定,我对e文很反感,所以就看了张洪斌那本书。挺有针对性的。接下来就是作题,1000多道吧,如有谁想要说话hansonxjy@21cn.com,我希望考的人都过,毕竟大家挣的都是辛苦钱。(完)
