SCJP考题14

转载 2007年10月13日 15:43:00

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,可惜只有69%!还是说说我准备考试的过程吧。   本人没有Java的实际开发经验(但有三五年的C++和Delphi开发经验,对OOP比较熟悉),为了考这试,准备了一个月...
  • u012402926
  • u012402926
  • 2016年03月30日 17:57
  • 149

多线程学习(四)线程的交互

转自:http://lavasoft.blog.51cto.com/62575/99157 Java线程:线程的交互   SCJP5学习笔记   线程交互是比较复杂的问题,SCJP要求不很...
  • qq_21909121
  • qq_21909121
  • 2016年05月31日 11:54
  • 360

ccf试题 工资计算

问题描述   小明的公司每个月给小明发工资,而小明拿到的工资为交完个人所得税之后的工资。假设他一个月的税前工资(扣除五险一金后、未扣税前的工资)为S元,则他应交的个人所得税按如下公式计算: ...
  • wqy20140101
  • wqy20140101
  • 2017年01月31日 16:59
  • 851

SCJP认证考试题集

http://wenku.baidu.com/view/a6585824a5e9856a5612606f.html?re=view 310-055SCJIP认证考试题集 Que...
  • xunmeng2002
  • xunmeng2002
  • 2015年06月29日 17:47
  • 854

读SCJP认识一下Java(一)

1. 定义了类、对象、属性、方法等,很明了直接: 2.关于变量名的合法定义的约定: 1、只能第一个字符,只能使用$符、字母、下划线开始,而不能使用数字;2、第一个字符后面没有限制,...
  • u012845809
  • u012845809
  • 2015年06月03日 17:30
  • 355

历年系统架构设计师考试之设计模式试题-2012年

2012年系统架构设计师考试下午试题中出现了一道25分的设计模式大题,上午仍旧是5道选择题,可以说是从2009年开考以来设计模式试题量最多的一年。Sunny友情建议:建议大家先做做这些试题,看是否能够...
  • LoveLion
  • LoveLion
  • 2014年03月17日 22:11
  • 15267

python生成随机的测验试卷

问题描述 假如你是一名老师,班上有45名同学,想要给他们进行一次测验,但又怕学生作弊,所以就想随机生成45份试卷,试卷题目都一样,只是随机打乱试题和答案顺序。 思路: 1.将所有题目和答...
  • tanggangzuiniu12
  • tanggangzuiniu12
  • 2018年01月11日 17:32
  • 23

考试篇(5.2) NSE4 题库 01. 入门 ❀ 飞塔 (Fortinet) 网络安全专家

Fortinet 飞塔网络安全专家 (4) 考试共 120 分钟,共 60 道英文选择题,答对 70% 计 42 道题为合格。...
  • meigang2012
  • meigang2012
  • 2017年04月23日 13:18
  • 804

寻址方式——汇编学习笔记(三)

操作数寻址方式有多种,其目的是缩短指令长度,扩大寻址空间,提高编程的灵活性。最基本的寻址方式有如下几种。    (1)隐含寻址            在指令中并不直接给出操作数...
  • cqkxboy168
  • cqkxboy168
  • 2013年05月30日 14:18
  • 507

SCJP之String的对象的相同与否

public class StringB {     public static void main(String[] args) {        String a ="JAVA...
  • janeness
  • janeness
  • 2014年04月23日 11:29
  • 418
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SCJP考题14
举报原因:
原因补充:

(最多只允许输入30个字)