以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Java/Eclipse 』  (http://bbs.xml.org.cn/list.asp?boardid=41)
----  SCJP Braindumps     05/15/2002  (http://bbs.xml.org.cn/dispbbs.asp?boardid=41&rootid=&id=31702)


--  作者:hongjunli
--  发布时间:5/3/2006 1:48:00 PM

--  SCJP Braindumps     05/15/2002
HI guy, This dump will definetely enable u to pass sun certified java progamer exam. I passed with 88% marks I could remember only these question in my exam. and If you know ur concepts then you are sure to pass. Download my dump and if you can take the exam soon then I am sure u will pass cause these question were in my exam. Dont waste your time

searching for java dumps just read this but dont memorise the answer just know the concept and this dump will definitely see u thru.

Good luck to all.


2. 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;}

/b


4. public class Foo{

public static void main(String args[]){

try{return;}

finally{ System.out.println("Finally");}

}

}

what is the result?

A. print out nothing

B. print out "Finally"

C. compile error

/b


12. public class Test{

public static void main(String[] args){

String foo=args[1];

Sring bar=args[2];

String baz=args[3];

}

}

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

/g

/ArrayIndexOutOfBoundsException


27. public class SychTest{

private int x;

private int y;

public void setX(int i){ x=i;}

public void setY(int i){y=i;}

public Synchronized void setXY(int i){

setX(i);

setY(i);

}

public Synchronized boolean check(){

return x!=y;

}

}

Under which conditions will check() return true when called from a different class?

A.check() can never return true.

B.check() can return true when setXY is callled by multiple threads.

C.check() can return true when multiple threads call setX and setY separately.

D.check() can only return true if SychTest is changed allow x and y to be set separately.

/c


public class Foo{

public static void main(String[] args){

StringBuffer a = new StringBuffer("A");

StringBuffer b = new StringBuffer("B");

operate(a,b);

System.out.println(a + "," + b);

}

static void operate(StringBuffer x,StringBuffer y){

y.append(x);

y = x;

} // end operate

}


What print?


a. "A,B" b. "A,A" c. "B,B"

d. "AB,B" e. "AB,AB" f, "A,AB"


Answer:

F


public class x implements Runnable{

private int x;

private int y;


public static void main(String args[] ){

x that = new x();

(new Thread(that)).start();

(new Thread(that)).start();

}

public synchronized void run(){

for( ; ; ){

x++;

y++;

System.out.Println("x=" + x + ", y=" +y);

}

}


a. An error at line 11

b. An error at line 7, 8

c. The program prints pairs of values for x and y that might not always be the same on the same line (for example "x=2, y=1")

d. The program prints pairs of values for x and y that are always the same on the same line (for example "x=1, y=1") in addition, each value appears twice (for example "x=1, y=1" followed by "x=1, y=1")

e. The program prints pairs of values for x and y that are always the same on the same line (for example "x=1, y=1") in addition, each value appears only once (for example "x=1, y=1", followed by "x=2, y=2)


1. public class x{

2. public object m(){

3. Object o=new Float(2.14F);

4. Object [] oa=new Object[1];

5. oa[0]=o;

6. o=null;

7. return o;

8. } // end m() method.

9. }


When is the Float object creation in line 3 eligible for garbage collection ?


a. just after line 5

b. just after line 6

c. just after line 7 (that is , as the method returns)

d. just after line 8 (that is, as the method ends)


1. abstract class AbstractIt{

2. abstract float getFloat();

3. }

4. public class AbstractTest extends AbstractIt{

5. private float f1 = 1.0f;

6. private float getFloat(){return f1}

7. }


what result?


a. compile success

b. An error at line 6

c. An error at line 4

d. An error at line 2


Answer:

b


2. import java.io.IOException;


public class ExceptionTest{

public static void main(String[] args){

try{

methodA();

}catch(IOException io){

System.out.println("caught IOException");

}catch(Exception e){

System.out.println("caught Exception");

}

}

public void methodA(){

throw new IOException();

}

}


what result?


a. The code will not compile

b. Output is "caught Exception"

c. Output is "caught IOException"

d. The program execute nomally whihout print a message


Answer:

a

non-static method methodA() cannot be refereced from a static context.


3. public class Foo{

public static void main(String[] args)[

try{ return;}

finally{ System.out.println("Finally");}

}

}


what result?


a. Print nothing

b. Print "Finally"

c. Not compiled and will Exception thrown

d. Not compile because catch block missing


Answer:

b


4. 1. class A implements Runnable {

2. int I;

3. public void run () {

4. try {

5. Thread.sleep(5000);

6. i=10;

7. }catch(InterruptedException e) {}

8. }

9. }

10.

11. public class Test {

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

13. try {

14. A a = new A();

15. Thread t = new Thread(a);

16. t.start();

17.

18. int j= a.i;

19.

20. }catch (Exception e) {}

21. }

22. }


Which statement at line 17 will ensure that j=10 at line 19


A. a.wait(); B. t.wait(); C. t.join(); D. t.yield();

E. t.notify(); F. a.notify(); G. t.interrupt();


Answer:

C


5. 1. public class SyncTest {

2. private int x;

3. private int y;

4. private synchronized void set X (int i){ x=i; }

5. private synchronized void set Y (int i){ y=i; }

6. public void setXY (int i) {set X(i); set Y(i); }

7. public synchronized boolean check() {return X != Y; }

8. }


Under which conditions will check() return when called from a different class. Choose one


A. check() can never return true

B. check() can return true when set XY is called by multiple threads

C. check() can true when multiple threads call set X and set Y separately

D. check() can only return true if synchTest is changed to allow x and y to be set separately


Answer:

C


6. Which is a method of the MouseMotionListener interface


A. public void mouseDragged(MouseEvent)

B. public boolean mouseDragged(MouseEvent)

C. public void mouseDragged(MouseMotionEvent)

D. public boolean mouseDragged(MouseMotionEvent)

E. public boolean mouseDragged(MouseMotionEvent)


Answer:

A


7. AnInterface is an interface.

AnAdapter0 is an non-Abstract, not-final with zero argument construter

AnAdapter1 is an non-Abstract, not-final without zero argument construter, but with a constructor to take one argument.


Which will create Anonymous class (choose two)


a)AnAdapter0 a = new AnAdapter0();

b)AnAdapter1 a = new AnAdapter1();

c)AnAdapter0 a = new AnAdapter0(5);

d)AnAdapter1 a = new AnAdapter1(5);

e)AnInterface a = new AnInterface(5);


Ans:

a and d are correct. B, c and e are wrong.


8. What is true about java.util.Arraylist (choose one)


a)The elements in the collection are ordered

b)The collection is guaranteed to be immutable.

c)The elements in the collection are guaranteed to be unique.

d)The elements in the collection are accessed using a unique key

e)The elements in the collection are guaranteed to be synchronized


Answer:

A is correct.

ArrayList implemnets all optional List operation.

b is wrong because lists typically allow duplicate elements. C is wrong this is Set facility. D is wrong because this is Map facility.

E is wrong, Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally ( refer documents )


9. 1.class A{

2. public int getNumber(int a){

3. return a +1;

4. }

5.}

6.class B extends A{

7. public int getNumber(int a){

8. return a + 2;

9. }

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

11. B b = new B();

12. System.out.println(b.getNumber(0));

13. }

14.}


a)compilation succeed and 1 is printed

b)compilation succeed and 2 is printed

c)An error at line 8 cause compilation fail

d)An error at line 12 cause compilation fail


Answer

B is correct.


10. Which two are equivelant


a)16/2^2

b)16>;>;2

c)16>;>;>;2

d)16/2

e)16*4


Answer:

b and c are correct.


11. public class TestAnonymous {


public static void main(String []args){

final StringBuffer s1=new StringBuffer();

final StringBuffer s2=new StringBuffer();


new Thread(){

//Anonymous class

public void run(){

synchronized(s1){

s1.append("A");


synchronized(s2){

s2.append(?B?;

System.out.println(s1);

System.out.println(s2);

} // end synch..(s2)

} // end synch..(s1)

} // end run

}.start(); // end anonymous class


new Thread(){

//Anonymous class

public void run(){


synchronized(s2){

s2.append("C");


synchronized(s1){

s1.append("D");

System.out.println(s2);

System.out.println(s1);

} // end synch..(s1)

} // end synch..(s2)

} // end run

}.start(); // end anonymous class

} // end main

} // end Test class


What is the result? ( choose two )


a)print ABBCAD

b)print CDDACB

c)print ADCBADBC

d)The output is a not-deterministic point because of a possible deadlock condition

e)The output is dependent on the threading model of the system the program is running on.


Answer:

a and b are the correct answer


int i=1;

int j=i++;

if( (i>;++j) && (i++==j) )

i += j;


What is the value of i after this code is finished?


Answer:

i = 2 is the correct answer.


which two CANNOT directly cause a thread to stop executing?


a. exiting from a synchronized block

b. calling the wait method

c. calling the notify method on an object

d. calling a read method on an InputStream object

e. calling the setPriority method on a Thread object


Answer:

I choose d and e


which is correct for declaring a character

a. char c = "a";

b. char c = '\'';

c. char c = ?caf??

d. char c = '\ucafe';

e. char c = 'u10100';

f. char c = (char)true;


Answer:

b, d


public interface Foo {

( ) int k=4;

}


which one the right to describe int k = 4 in interface foo? (choose three)


a. abstract

b. private

c. volatile

d. protected

e. static

f. public

g. transient

h. final


Answer:

I choose e,f and h


switch(i) {}

which one i will accept it?


a. byte

b. long

c. duoble

d. float


Answer:

A

The accepted values for I are: byte, int, short, char


Given an Action Event which method allows you to identify the affected Component?


a. public Component getClass() b. pubilc Object getSource()

c. public Component getSource() d. public component getTarget()


Answer:

b


int i=1; int j=10;


do{

if(i>;j) continue;

j--;

}while(++i<6);


After execution, what are the value for i and j?


a. i=6 and j=5

b.i=5 and j=5

c.i=6 and j=4

d.i=5 and j=6

e.i=6 and j=6


Answer:

correct answer is ( a ): i = 6 and j = 5


String s=&quot;base&quot;;

s.substring(2,4);

s.concat(&quot;xxxx&quot;);

s+=&quot;ball&quot;


What is the result of s? (note: there was a TextField to write your answer into it )


Answer:

baseball


which statement is true? ( choose one )


a. the Error class is a RuntimeException

b. No exceptions are subclass of Error

c. Any statement that may throw an Error must be enclosed in a try block

d. Any statement that may throw an Exception must be enclosed in a try block

e. Any statement that may throw a RuntimeException must be enclosed in a try block


Answer:

I am not sure if < b >; is correct or not.


byte b = 127;

byte c = 126;

byte a = b + c;


what is the result?


a. a will equal to 253

b. compile error

c. exception at 1

d. exception at 2


Answer:

b is correct. compile error: possible loss of precision. To solve this problem, cast it

byte a = (byte)(b + c);


28.

import java.awt.*;


public class Test extends Frame {

public static void main(String [] args) {

new Test();

}

Test () {

add( new Label(?Hello? );

add( new TextField(?World? );

add( new Button(?Ok? );

pack();

show();

}

}


what is the result?


a. compile error

b. three components will appear, Label at North, TextField at South and Button at Center.

c. only one Button at the Center

d. Frame will appear, but nothing there

e. exception will be thrown


Answer:

C


String foo = ?blue?

boolean [] b = new boolean[10];

if(b[0])

foo = ?green?

System.out.println(?foo: ?+ foo);


What will foo print?


Answer:

Foo: blue


String s = ?hello?

s.subString(0,4);

s.concat(?world);

System.out.println(?s: ?+ s);


What is the result?


Answer:

S: hello

Strings are immutable.


private class Test {???}

public class Test2 extends Test {??..}


what is the result? (there are options to choose)


Answer:

Compile error because private not allowed to declare classes.


32.

protected class Test {???}

public class Test2 extends Test {??..}


what is the result? (there are options to choose)


Answer:

Compile error because protected not allowed to declare classes.


78. Which will return an int value very nearer to and not greater than

the given double value?


a) int a=(int)Math.max(double)

b) int a=(int)Math.min(double)

c) int a=(int)Math.ceil(double)

d) int a=(int)Math.floor(double)

e) int a=(int)Math.round(double)


Ans d


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

int i=1;

int j=10;

do{

if(i>;j)

continue;

j - -;

} while(++i<6);

System.out.println(&quot;i= &quot;+i+&quot; j= &quot;+j);

}

What will be the output?


a) i=4 , j=5

b) i=5 , j=6

c) i=5 , j=5

d) i=4 , j=6

e) i=6 , j=5


Ans e


Q#14 method of mousemotionlistener interface

A. public void mouseDragged(MouseEvent)

B. public boolean mouseDragged(MouseEvent)

C. public void mouseDragged(MouseMotionEvent)

D. public boolean mouseDragged(MouseMotionEvent)

E. public boolean mouseDragged(MouseMotionEvent)


Answer:

A


Q#19 output of the following program

String foo = &quot;blue&quot;;

boolean [] b = new boolean[10];

if(b[0]) {

foo=&quot;yellow.&quot;;}

System.out.println(foo);

Ans-blue


246. Which of the following two declarations used to read a file

called ?Test.txt?

a) RandomAcceesFile raf=new RandomAcceesFile(?Test.txt?;

b) InputStream is = new FileInputStream(?Test.txt?;

c) InputStream is = new

DataInputStream(FileInputStream(?Test.txt?true));

d) FileInputStream fis = new FileInputStream(new File(?Test.txt?);

e) FileoutputStream fos = new FileoutputStream(new File(?Test.txt?);

f) OutputStream os = new FileoutputStream(new File(?Test.txt?false));


Ans BD


252. How to append to file ?Test.txt? (Select two)

a) FileOutputStream fis = new FileOutputStream ( ?Test.txt? true);

b) OutputStream os = new FileOutputStream ( ?Test.txt? ?append?;

c) FileOutputStream fis = new FileOutputStream ( ?Test.txt? ?true?;

d) FileOutputStream fis = new FileOutputStream (new File( ?Test.txt?);

e) OutputStream os = new OutputStream (new File( ?Test.txt?, true);


Ans AD


27.A socket object has been created and connected to a standard intern

et sevice on a remote network server.Which construction give the most

suitable means for reading ASCII data one line at a time from the sock

et?


A.InputStream in=s.getInputStream();


B.DataInputStream in=new DataInputstream(s.getInputStream());


C.ByteArrayInputStream in=new ByteArrayInputStream(s.getInputStream())

;


D.BufferedReader in=new BufferedReader(new InputStreamReader(s.getInpu

tStream()));


E.BufferedReader in=new BufferedReader(new InputStreamReader(s.getInpu

tStream()),&quot;8859-1&quot;);


2. Which gets the name of the parent directory of file &quot;file.txt&quot;?


a. String name = File.getParentName(&quot;file.txt&quot;)


b. String name = (new File (&quot;file.txt&quot;).getParent());


c. String name = (new File (&quot;file.txt&quot;).getParentName());


d. String name = (new File (&quot;file.txt&quot;).getParentFile());


e. Directory dir = (new File (&quot;file.txt&quot;).getParentDir());


String name = dir.getName();



W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
60.547ms