SCJP考题14

615. Given the following class definition:

public class Droitwich{

class one {

private class two{

public void main(){

System.out.println("two");

}

}

}

}

Which of the following statements are true?

A. The code will not compile because the classes are nested to more than one level

B. The code will not compile because class two is marked as private

C. The code will not compile and output the string two at runtime

D. The code will not compile without error

正确答案: D

 

623. What is the result from the following code when you run?

import java,io.*;

calss A {

A()throws Exception{

System.out.println("execrting class A constructor");

throw mew IOException();

}

}

public class B extends A{

B(){

System.out.println("Execrting class B constructor");

}

public static void main(String args[]){

try{

A a=new B();

}catch(Exception c){

System.out.println(c.getMessage());

}

}

}

Select the one right answer.

A. Executing class A constructor

B. Executing class B constructor  

C. Runtime error

D. Compile time error

 

 

626. What is the reason using $ in inner class representation?

A. Because the inner classes are defined inside of amy class

B. Due to the reason that inner classes can be defined inside any method

C. This is convention adopted by(被。。。。采用) Sun,to insure(确保) that there is no ambiguity(含糊的) between packages and inner classes.

D. Because if use getClass(),getName() will gives you the error

 

 

633. Which of the following statements are true?

A. An anonymous(匿名的) class cannot have any constructors.

B. An anonymous class can only be created within the body of a method.

C. An anontmous class can only access static fields of the enclosing class.

D. An anontmous class instantiated and declared in the same place.

正确答案: AD

 

 

 

646. In the code if you compile as "java hello4.java" following files will be generated.

1  import java applet.Applet;

2  import java.awt*;

3  import java.awt.event.*;

4  public class hello4 extends Applet {

5  public void int(){

6  add(new myButton("BBB"));

7  }

8  public void paint(Graphics screen){

9  }

10 class myButton extends Button{

11 myButton(String label){

12 super(label);

13 }

14 public String paramString(){

15 return srper.parmString();

16 }

17 }

18 public static void main(String[] args){

19 Frame myFrame=new Frame(

20 "hello4");

21 myFrame.setSize(300,100);

22 Applet myApplet=new hello4();

23 Butten b=new Button("My Button");

24 myApplet.add(b);

25 b setLabel(b getLabel()+"New");

26 //myButton b1=new myaButton("PARAMBUTTON");

27 System.out.println(b1.paramString());

28 myFrame.set(myApplet);

29 myFrame.addVisible(true);

30 myFrame.addWindowListener(new WindowAdapter()){

31 public void windowClosing(WindowEvent e){

32 System.exit(0);}});

33}

34 }//End hello4 class.

Select the one reght answer.

A. hello4.class,myButton.class,hello4.lass

B. hello4.class,hello4$myButton.class,hello4$1.class

C. hello4.class.hello4$myButton.class

正确答案:B

 

 

 

647. The following code will give:

1: class Test

2: {

3: void show()

4: {

5: System.out.println("non-static method in Test");

6: }

7: }

8: public class Q3 extends Test

9: {

10:static void show()

11:{

12:System.out.println("Overridden non-static method in Q3");

13:}

14:

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

16:{

17:Q3 a=new Q3();

18:}

19:}

Select the one right answer

A. Compilation error at line 3.

B. Compilation error at line 10.

C. No compilation error,but runtime exception at line 3.

D. No compilation error,but runtime exception at line 10.

正确答案:B

 

 

649. What is the output of the following code?

1:  class Test

2:  {

3:  Test(int i)

4:  {

5:  System.out.println("Test("+i+")");

6: }

7: }

8:

9: public class Q12

10:{

11:static Test t1=new Test(1);

12:

13:Test t2=new Test(2);

14:

15:static Test t3=new Test(3);

16:

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

18:{

19:Q12Q=new Q12();

20:}

21:}

Select the one right answer.

A. Test(1)

Test(2)

Test(3)

B. Test(3)

Test(2)

Test(1)

C. Test(2)

Test(1)

Test(3)

D. Test(1)

Test(3)

Test(2)

正确答案:D

 

 

 

 

648. What will happen if you compile/run the following code?

1: public class Q11

2: {

3: static String str1="main method with String[] args";

4: static String str2="main method with int[] args";

5:

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

7: {

8: System.out.println(str1);

9: }

10:

11:public static void main(int[] args)

12:{

13:System.out.println(str2);

14:}

15:}

Select the one right answer.

A. Duplicate(复制) method main(),compilation error at line 6;

B. Duplicate method main(),compilation error at line 11;

C. Prints"main method with main String[]args".

D. Prints"main method with main int[]args".

正确答案:C

 

 

 

652. What is displayed when the following code is executed?

class parent{

private void method1(){

System.out.println("Parent's method1()");

}

public void method2(){

System.out.println("Parent's method2()");

method1();

}

}

class Child extends Parent{

Public void method1(){

System.out.println("Child's method1()");

}

public static void main(String args[]){

Parent p=new Child();

p.method2();

}

}

Select the one right avswer.

A. Compile-time error

B. Run-time error

C. Prints:Patent's method2() Parent's method1()

D. Prints:Patent's method2() Child's method1()

正确答案:C

 

653. What is displayed when the following code is executed?

class Paten{

void method1(){

System.out.println("Parent's method1()");

}

public void method2(){

System.out.println("Parent's method2()");

method1();

}

}

class Child extends Parent{

public void method1(){

System.out.println("Child's method1()");

}

public static void main(String args[]){

Parent p=new Child();

p.method2();

}

}

Select the one right answer.

A. Compile-time error

B. Run-time error

C. Prints:Parent's method2() Parent's method1()

D. Prints:Parent's method2() Child's method1()

正确答案:D

 

 

 

 

 

 

666. Examine the following class definition:

public class Test{

public static void test(){

print();

}

public static void print(){

System.out.println("Test");

}

public void print(){

System.out.println("Another Test");

}

}

What is the result of compiling this class:

Select the most appropriate answer.

A. A successful compilation.

B. A warning stating that there is a duplicated method.

C. An error stating that there is a duplicated method.

D. An error stating that the method test() will call one or other of the print() methods.

 

 

 

668. Carefully examine the following class:

public class Test{

public static void main(String args[]){

if (true){

Test t=new Test();

System.out.println("Done the test");

}

System.out. println("The end");

}

}

Select the most appropriate answer.

A. Prints out "Done the test"and nothing else.

B. Prints produces no output but terminates correctly.

C. Program does not terminates correctly.

D. The program will not compile.

E. The program generates a runtime exception.

F. The program prints out "The end"and mothing else.

G. The program prints out"Done the test"and "The end"

 

 

 

670.What a static inner class can access ? (selec one)

A.Any variables in the enclosing scope

B.Final variables in the enclosing scope

C.Static variables declared in side the method

D.上述答案都不对

 

 

 

679.Given the following code:

    1.class Happy {

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

    3.public class Sad {

    4.public void methodA() {

    5.System.out.println("inside sad");

    6.}

    7.}

    8.System.out.println("inside happy");

    9.}

    10.}

What will be the output?

A. compilation error at line no.3

B. compilation error at no.4

C. compilation error at line no.5

D.compilation succeeds but runtime exeption

E.clean compile and give the output "inside happy"

 

 

 

683. Given the extends Happy{

class Happy{

public int getLength(){

System.out.println("int version");

}

}

class Life extends Happy{

public long getLength(){

System.out.println("long version");

}

public static void main(String args[]){

Happy e=new Life();

e.getLength();

}

}

Which method gets executed?

A. int version

B. long version

C. compile time error

D. run time exception

E. clean compile but no output

 

 

 

 

 

Run()方法是什么的,他什么时候被调用

     

687. What appears in the standard output when you run the Dots class?

class Test impltements Runnable{

DotThread t;

public static void main(String[]args){

Test d=new Test();

d.t=new DotTgread();

}

public void init(){

t.start();

t=new DashThread().start();

}

}

class DotThread extends Thread{

public void run(){

for(int index=0;index<100;index++)

System.out.print(".");

}

}

class DashThread extends Thread{

public void run(){

for(int index=0;index<100;index++)

System.out.print("-");

}

}

Select the one right answer.

A. nothing

B. 100 dots(.)

C. 200 dots(.)

D. 100 dashes(-)

E. 100 dots(.)and 100 dashes(-)

 

 

694. Which statements are true about threads?

A. A thread can be created only by subclassing java.lang.Thread.

B. Invoking the suspend() method stops a thread so that it cannot be restarted.

C. The java interpreter's natural exit occurs when no non-daemon threads remain alive.

D. Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistemt state.

 

696. Given the following class:

class Test {

public int startHere=1;

public int endHere=100;

public startic void main(String[] args){

new Test().go();

}

void go(){

//A

Thread 1=new Thread(a);

t.start();

}

}

What block of code can you replace at line A above so that this program will count from startHere to endHere?

Select all valid answers.

A. Runnable a = new Runnable(){

public void run(){

for (int i=starHere;i<=endHere;i++){

System.out.println(i);

}

}

};

B. implements Runnable{/

public void run(){

for(int i=starHere;i<=endHere;i++){

System.out.println(i);

}

}

};

C. Thread a=new Thread(){

public void run(){

for(int i=starHere;i<=endHere;i++)|

System.out.prinln(i);

}

}

};

 

 

 

704. Under what circumstances might you use the yield method of the Thread class?

A. To call from the currently running thread to allow another thread of the same or higher priority to run.

B. To call on a waiting thread to allow it to run

C. To allow a thread of higher priority to run

D. To call from the currently running thread with a parameter designating which thread should be allowed to run

 

 

 

705. Which of the following statements about threading are true?

A. You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements Runnable.

B. You can obtain a mutually exclusive lock on any object.

C. A thread can obtain a mutually exclusive lock on a synchronized method of an object.

D. Thread scheduling algorithms are platform dependent.

 

 

 

711. Select all the exceptions thrown by wait() method of an Object class, which you can replace in the place of xxx legally?

class Test implements Runnable{

public void run(){

System.out.println("Execrting run() method");

myTest();

}

public synchronized void myTest(){

  try{

wait(-1000);

System.out.println("Execrting the myTest() method");

}XXX

}

}

public class MyTest{

public static void main(String args[]){

Test t=new Test();

Thread th=new Thread(t);

th.start();

}

}

Select the one right answer.

A. catch (InterruptedException ie){}

B. catch (IllegalArgumentException i1){}

C. catch (IllegalMonitorStateException i1){}

D. Only catch (InterruotedException e){} exception

 

718. The method resume() is responsible for resuming which thread's execution?

A. The thread which is stopped by calling method stop()

B. The thread which is stopped by calling method steep()

C. The thread which is stopped by calling method wait()

D. The thread which is stopped by calling method suspend()

 

712. There are 20 threads are waiting in the waiting pool with same priority. how can you invokes 15th thread from the wailing pool?

A. By calling resume() method

B. By calling interrupt() method

C. Calling call() method

D. By calling notify(15)method on the thread instance

E. None of the above

 

 

 

721. What happens when you try to compile and run the following application?

public class Test{

public static void main(String[] args){

new Test();

}

Test(){

Test alias1=this;

Test alias2=this;

synchronized(alias1){

try{

slias2.wait();

System.out.println("DONE WAITING");

}

Catch(InterruptedException e){

System.out.println("INTERR UPTED");

}

catch(Exception e){

System.out.println("OTHER EXCEPTION");

}

finally{

System.out.println("FINALLY");

}

}

System.out.println("ALL DONE");

}

}

Choose all correct options.

A. The application compiles but doesn't print anything.

B. The application compiles and print"DONE WAITING"

C. The application compiles and print "FINALLY"

D. The application compiles and print "ALL DONE"

E. The application compiles and print "INTERRUPTED"

正确答案: A

 

 

 

726. What is the result of compiling and executing the following Java class:

public class Test extends Thread{

public void run(){

System.out.println("In run");

suspend();

resume();

System.out.println("Leaving run");

}

public static void main(Syring args[]){

(new Test()).start();

}

}

Select the most appropriate answer.

A. Compilation will fail in the method main.

B. Compilation will fail in the method run.

C. A warning will be generated for method run.

D. The string" In run" will be printed to standard out.

E. Both strings will be printed tp standard out.

F. Nothing will happen.

正确答案: D

 

732. Which of the following statements are true?

A. all the threads created in a class will come to an end at the same tine.

B. you can stop a thread indefinitely if you wish to.

C. you can start a thread only by extending the Thread class.

D. multiple threads accessing same variable will lead to producing junk(not the exact word )data.

E. JVM exits after the main() thread is exited even if there might be some threads running.

正确答案: B D

 

 

 

 
阅读更多
个人分类: SCJP考题
想对作者说点什么? 我来说一句

SCJP题库(附答案)

2016年05月24日 3.58MB 下载

没有更多推荐了,返回首页

不良信息举报

SCJP考题14

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭