现在的位置: 首页 > 综合 > 正文

SCJP考题11

2013年02月24日 ⁄ 综合 ⁄ 共 5383字 ⁄ 字号 评论关闭

564. What will appear in the standard output when you run the Tester class?

class Tester{

int var;

Tester(int var){

this ("hello");

}

Tester(String s){

this();

System.out.println(s);

}

Tester(){

System.out.println("good-bye");

}

public static void main(String[]args){

Tester t=new Tester(5);

}

}

Select all valid answers.

A. nothing

B. "hello"

C. 5

D. "hello"followed by "good-bye"

E. "good-bye"followed by "hello"

正确答案:E

 

565. Imagine there are two exception classes called Exception 1 and Exception2 that descend from(从——下来) the Exception class,Given these two class definitions:

class First{

void test()throws Exceotuib1,Exceotuib2(...)

}

class Second extends First{

void test(){...}

Create a class called Third that extends Second and defines a test()method.What exceptions can Third's test() method throw?

Select all valid answers.

A. Exception 1

B. Exception 2

C. no checked exception 3

D. any exceptions declared in the throws clause of the Third's test()method.

正确答案:C

 

566. Which methods are correct overloading methods of the following method:

public void dxample(){...}

A. public void example(int m){...}

B. public int example(){...}

C. public void example2(){...}

D. public int example(int m,float f){...}

正确答案:AD

 

567. Given the following fragment of code:

public class Base{

int w,x,y,z;

public Base(int a,int b){

x=a;

y=b;

}

public Base(int a,int b,int c,int d){

//assignment x=a,y=b

w=d;

z=c;

}

}

Which expressions can be used at the point of //assignment x=a,y=b?

A. Base(a,b);

B. x=a,y=b;

C. x=ay=b;

D. this(a,b);

正确答案:CD

 

568. The following code will give:

1: class Test{

2: static void show()

3: {

4: System.out.println("Static method in Test");

5: }

6: }

7: public class Q4 extends Test{

8: void show()

9: {

10:System.out.println("Overridden static method in Q4");

11:}

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

13:{

14:}

15:}

Select all valid answers.

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

 

569. Given the following code:

1) class Example{

2) String str;

3) public Example(){

4) str="example";

5) }

6) public Example(String s){

7) str=s;

8) }

9) }

10)class Demo extends Example{

11)}

12)public class Test{

13)public void f(){

14)Example ex = new Example("Good");

15)Demo d=new Demo("Good");

16)}

Which line will cause an error?

A. line 3

B. line 6

C. line 10

D. line 14

E. line 15

正确答案:E

 

570. Given the following class definition in one source file:

class Base{

public Base(){//...}

public Base(int m){//...}

public void fun(int n){//...}

}

public class Child extends Base{

//member methods

}

Which methods can be added into the Child class correctly?

A. private void fun(int n){//...}   范围变小

B. viod fun(int n){//...}

C. protected void fun(int n){//...}

D. public void fun(int n){//...}

E. public m(){//...}

正确答案CD

 

571. Which statements are correct?

A. In Java single inhetance is allowed,which makes code more reliable

B. A subclass inherits all methods(including the constructor)from the superclass   私有的??

C. A class can implement as many interfaces as needed

D. When a class implements an interface,it can define as many methods of the interface as needed

正确答案:AC

 

572. in the Test.Java source file,which are correct class definitions?

A. public class test{

public int x=0;

public test(int x)

{

this.x=x;

}

}

B. public class Test{

public int x=0;

public Test(int x){

this.x=x;

}

}

C. public class Test extends T1,T2{

public int x=0;

public Test(int x){

this.x=x;

}

}

D. public class Test extends T1{

public int x=0;

public Test(int x){

this.x=x;

}

}

E. protected class Test extends T2{

public int x=0;

public test(int x){

this.x=x;

}

}

正确答案:BD

 

573. Given the following class definition:

class A{

protected int i;

A(int i){

this.i=i;

}

}

Which of the following sould be a valid inner class for this class?

Select all valid answers.

A. class B()

B. class B extends A{}

C. class B extends A{B(){System.out.println("i="+i);}}

D. class B{class A{}}

E. class A{}

正确答案:A

(本题原文中没提供正确答案)

 

574. The following code is entire(全部) contents of a file called Example java,causes precisely(正好) one error during compilation:

1) class SubClass extends BaseClass{

2) }

3) class BaseClass(){

4) String str;

5) public BaseClass(){

6) System.out.println("ok");}

7) public BaseClass(String s){

8) str=s;}}

9) public class Example{

10)Public void method(){

11)subClass s=new SubClass("hello");

12)BaseClass b=new BaseClass("world");

13)}

14)}

Which line would be cause the error?

A. 9

B. 10

C. 11

D. 12

正确答案:C

 

575. The piece of preliminary analsis(初步的分析) work describes a class that will be used frequently in many unrelated(无关的) parts of a project."The polygon(多边形) object is a drawable.A polygon has vertex(顶点,最高点) informtion stored in a vector,a color,length and width."

Which Data type would be used?

A. Vector

B. int

C. String

D. Color

E. Date

正确答案:ABD

 

576. "The Employee object is a person,An Employee has appointment(约会,指定) store in a vector,a hire date and a number of dependent"short answer:use shortest statement declare a class of Employee.

Fill in the blank.

正确答案:public class Employee extends Person

 

577. Give the following class defination inseparate(不分开的) source files:

public class Example{

public Example(){

//do something}

protected Example(int i){

//do something}

protected void method(){

//do something}

}

public class Hello extends Example{

//member method and member variable

}

Which methods are corrected added to the class Hello?

A. public void Example(){}

B. public void method(){}

C. protected void method(){}

D. private void method(){}

正确答案:ABC

 

578. What right when you try to compile and run the following program?

class Mystery{

String s;

public static void main(String[]args){

Mystery m=new Mystery();

m.go();

}

void Mystery(){

s="constructor";

}

void go(){

System.out.println(s);

}

}

Select the one right answer.

A. this code will not compile

B. this code compliles but throws an exception at runtime

C. this code runs but nothing appears in the standard output

D. this code runs and "constructor"in the standard output

E. this code runs and writes "null"in the standard output

正确答案:E

 

579. Given this skeleton(框架) of a class currently under construction:

public class Example{

int x,y,z;

public Example (int a,int b){

//lots of complex computation

x=a; y=b;

}

抱歉!评论已关闭.