分享
 
 
 

非常不错的SCJP真题回忆

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

PART 1

1.public static void main(String args[]) {

Boolean a[]=new Boolean[4];

int I= 1;

System.out.println(a[I]); }

What will be printed?

Compilation Error in Line 2

Compilation Error in line 4

Exception in Line 4

Will print true

Will print false

Will print null

Ans:F

2.

public static void main(String args[]) {

Integer b= new Integer(10);

Add(b);

System.out.println(b.intvalue());

}

void Add(Integer b)

{

int I= b.intvalue();

I+=3;

b= new Integer(I)

}

What will be printed out?

Will print 13

Will print 10

Compilation Error in Line 4 ?. implicit conversion to Integer to

String is not possible

Compilation Error in line 10 you can't re initialize a Wrapper

class

Exception in Line 10

Ans:b

class text{

public static void main(String args[])

{

String a =args[1];

String b =args[2];

String c =args[3];

}

}

if you will execute Java text cat dog sheep what will be the value of

the 'c' ?

cat

dog

sheep

Compilation Error

Exception will occur

Ans:E

4. public static void main(String args[])

{

Float f=new Float(4.2f);

Float c;

Double d=new Double(4.2);

float fl=4.2f;

c=f;

}

which will return true?. Select all

f.equls(d)

c==f

c==d

c.equls(f)

Ans:B,D

5. public static void main(String args[])

{

String s;

System.out.println("s = "+s);

}

what will be printed out?

Compilation Error

An Exception will occur

Will print s= null

Will print s=

Ans:A

6. class s extends Thread{int j=0;

public void run() {

try{Thread.sleep(5000);}

catch(Exception e){}

j=100;

}

public static void main(String args[])

{

s t1=new s();

t1.start();

System.out.println(t1.j);

}

}

what you have to do to ensure that 'j' will print 100

you have make t1 as Daemon Thread

You have join the t1 to main

You have to suspend the main when the thread starts and resume it after

the value of 'j' is set to 100

You have to interrupt the main thread

Ans:B

7. What will happen if you compile/run this code?

1: public class Q1 implements Runnable

2: {

3: public void run(String s)

4: {

5: System.out.println("Before start Thread :"+s);

6:

7: System.out.println("After stop of Thread :"+s);

8: }

9:

10: public static void main(String[] args)

11: {

12: Q1 a = new Q1();

13: Thread t=new Thread(a);

14: t.start();}

15: }

A) Compilation error at line 1

B) Runtime exception at line 13.

C) Compilation error at line 14

D) Prints "Before start of Thread "

After Start of Thread

Ans:A

8. class s implements Runnable{

int x=0,y=0;

int addX(){x++; return x;}

int addY(){y++; return y;}

public void run()

{

for(int i=0;i

System.out.println(addX()+""+addY());

}

public static void main(String args[])

{

s run=new s();

Thread t1=new Thread(run);

Thread t2=new Thread(run);

t1.start();

t2.start();

}

}

Compile time Error There is no start method

Will print in this order 11 22 33厖

Will print but not exactly in an order (eg: 123124 3厖)

Will print in this order 12 3厖123厖

Will print in this order 123厖?.

Ans:C

9.

class s implements Runnable{

int x=0,y=0;

synchronized void addX(){x++; }

synchronized void addY(){y++; }

void addXY(){x++;y++;}

boolean check() { return (xy)? true:false;)

public void run()

{

////

System.out.println(check()); }

public static void main(String args[])

{ s run=new s();

Thread t1=new Thread(run);

Thread t2=new Thread(run);

t1.start();

t2.start();

}

}

If this methods are called in which order the check will return true?

Select all that apply

call addX() and addY() simultaneously for number of times in run()

call addY() and addX() simultaneously for number of times in run()

all addXY() for number of times in run()

Ans:B,C

10. What is the name of the method used to start a thread execution?

A. init();

B. start();

C. run();

D. resume();

Ans:B

11. Which two methods may not directly cause a thread to stop

executing?

A. sleep();

B. stop();

C. yield();

D. wait();

E. notify();

F. notifyAll()

G. synchronized()

Ans:EF

12. class Outer{

class Inner{}

}

How will you create an instance of Inner Class out side? Select 2

Inner a= new Inner();

Outer o= new Outer();Inner a= new o.Inner();

Outer o= new Outer();Outer.Inner a= new o.Inner();

Outer.Inner a= new Outer().new Inner();

Ans:CD

13. What a static inner class can Access select one

A. Any variables in the enclosing scope

B. Final variables in the enclosing scope

C. Static variables declared in side the method

D. Static variables declared in side the outer class

Ans:D

14. What is true about inner class? Select one

an Inner class can access all variables in the any enclosing scope

an Inner class can access all variables in the enclosing scope

an inner class can be declared as private

an Anonymous inner class can be extended from class and can implement

an interface

Ans:C

15. A ----- is a class that is a collection which cannot contain any

duplicate elements which maintains its elements in ascending order.

SortedSet

Set

Sorted Map

Collection

TreeSet

Ans: A

16. What is true about Map select one

A map will order the elements in an order according the key

A map will use unique key to store value

A map will use unique key to identify value inside the map

Ans:C

17. Which Method Returns the parent part of the pathname of this File

object, or null if the name has no parent part?

getParent()

getParentDir()

getParentDirectory()

parentDirectory()

Ans:a

18. Which class should be used in situations that require writing

characters rather than bytes.

LineNumberWriter

PrintWriter

PrintStream

PrintOutputReader

Ans:B

19. To Write End of a File f=new File(C:\\hello.txt");

new RandomAccessFile(f,"rw").writeByte(?;

FileInputStream fis=new FileInputStream(f,true);

DataInputStream d=new DatainputStream(fis);

d.writeBytes(?

FilterInputStream fis=new FilterInputStream(f,true);

DataInputStream d=new DatainputStream(fis);

d.writeBytes(?

D. FileOutputStream fis=new FileOutputStream(f);

DataOutputStream d=new DataOutputStream(fis);

d.writeBytes(?

E

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有