SCJP考题9

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

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

class Tester{

int var;

Tester(double var){

This.var=(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 Exception1 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 exceptions

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 example(){...}

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=a,y=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 inheritance is allowed, which makes code more reliable

B. A subclass inherits all methods(including he 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 necded

正确答案: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){

rhia.i=i;

}

}

Which of the following would 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 analysis 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 information 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 definition in separate 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 happens 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 compiles 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;

}

public Example(int a,int b,int c){

//do everything the same as single argument

//version of constructor

//including assignment x=a,y=b,z=c

z=c;

}

}

What is the most concise way to code the "do everything..."part of the constructor taking two arguments?

Fill in the blank.

正确答案:this(a,b);

 

580. Which are correct class declarations? Assume in each case that the text constitutes the entire contents of a file called Fred java?

A. public class Fred{

public int x=0;

public Fred(int x){

this.x=x;

}

}

B. public class fred{

public int x=0;

public Fred(int x){

this x=x;

}

}

C. public class Fred extends

MyBaseClass, MyOtherBaseClass{

public int x=0;

public Fred(int xval){

x=xval;

}

}

D. public class Fred{

private int x=0;

private Fred(int xval){

x=xval;

}

}

E. import java awt.*;

public class Fred extends Object{

int x;

private Fred(int xval){

x=xval

}

}

正确答案:AE

 

581. Look the inheritance relation:

In a source of java have the following line:

woman w=new man();

what statement are corrected?

A. The expression is illegal.

B. Compile corrected but running wrong.

C. The expression is legal.

D. Will construct a woman's object.

正确答案:A

 

582. The following is a program.

1) class Exsuper{

2) String name;

3) String nick_name;

4)

5) public Exsuper(String s.String t){

6) name = s;

7) nick_name = t;

8) }

9)

10)public String toString(){

11)return name;

12)}

13)}

14)

15)public class Example extends ExSuper{

16)

17)public Example(String s.String t){

18)super(s,t);

19)}

20)

21)Public String toString(){

22)return name +"a.k.a"+nick_name;

23)}

24)

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

26)Exsuper a=new Example("First","1st")

27)Exsuper b=new Example("Second","2nd")

28)

29)System.out.println("a is"+a.toString());

30)System.out.println("b is"+b.toString());

31)}

32)}

What happens when the user attempts to compile and run this program?

A. A Compiler error occurs at line 21

B. An object of type ClassCastException is thrown at line 27

C. The following output:

   a is First

   b is second

D. The following output:

   a is First

   b is Secong a.k.a 2nd

E. The following output:

   a is First a.k.a 1st

   b is Second a.k.a 2nd

正确答案:D

 

583. Which statement is true about an inner class?

A. It must be anonymous

B. It can not implement an interface

C. It is only accessible in the enclosing class

D. It can access any final variables in any enclosing scope.

正确答案:D

 

584. Which best describes the requirements of a fully encapsulated class?

A. Methods must not be private.

B. Variables must not be public.

C. The class must be marked final

D. Public methods are all marked final.

E. Modification of the objects state is only possible using method calls.

正确答案:E

 

585. Given the following class definition:

class A{

public int x;

private int y;

class B{

protected void method(){

}

class C{

private void method2(){

}

}

}

}

class D extends A{

public float z;

}

What can method2() access directly, without a reference to another to another instance?

Select all valid answers.

A. the variable x defined in A

B. the variable y defined in A

C. method1 defined in B

D. the variable z defined in D

正确答案:ABC

 

586. Given this interface definition:

interface A{

int method1(int i);

int method2(int j);

}

Which of the following classes implements this interface and is not abstract?

A. clasas B implements A{

int method1(){...}

int method2(){...}

}

B.class B{

int method1(int i){...}

int method2(int j){...}

}

C. class B implements A{

int method1(int i){...}

int method2(int j){...}

}

D. class B extends A{

int method1(int i){...}

int method2(int j){...}

}

 

E. class B implements A{

int method1(int i){...}

int method2(int j){...}

}

正确答案:CE

 

587. Write a statement for a constructor that invokes the no-args, default constructor in its super class.

Fill in the blank

正确答案:super();

 

588. What happens 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 compiles but throws an exception at runtime

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

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

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

正确答案:E

 

589. Why won't the following class compile?

class A{

private int x;

public static void main(String[] args){

new B();

}

class B{

B(){

System.out.println(x);

}

}

}

Select the one right answer.

A. Class B tries to access a private variable defined in its outer class

B. Class A attempts to create an instance of B when there is no current instance of class A.

C. Class B's constructor must be public.

正确答案:B

 

590. What will happen if you try to compile and execute B's main() method?

class A{

int i;

A(int i){

this i=i*2;

}

}

class B extends A{

public static void main(String[] args){

B b = new B(2);

}

B(int i){

System.out.println(i);

}

}

Select the one right answer.

A. The instance variable i is set to 4

B. The instance variable i is set to 2

C. The instance variable i is set to 0

D. This code will not compile

正确答案:D

 

591. Which of the following statements are true?

A. Methods cannot be overridden to be more private

B. Static methods cannot be overloaded

C. Private methods cannot be overloaded

D. An overloaded method cannot throw exceptions not checked in the base class

正确答案:A

 

592. What will happen if you attempt to compile and run the following code?

class Base {}

class Sub extends Base {}

class Sub2 extends Base {

public class CEx{

public static void main(String argv[]){

Base b=new Base();

Sub s=(Sub)b;

}

}

Select the one right answer.

A. Compile and run without error

B. Compile time Exception

C. Runtime Exception

正确答案:C

 

593. Which of the following methods can be legally inserted in place of the comment?

class Base{

public void amethod(int i){ }

}

public class Scope extends Basc{

public static void main(String argv[]){

}

//Method Here

}

Select the one right answer.

A. void amethod(int i) throws Exception {}

B. void amethod(long i) throws Exception {}

C. void amethod(long i){}

D. public void amethod(int i) throws Exception {}

正确答案:BC

 

594. Gives the following code:

public class MyClass1{

public static void main(String argv[]){ }

/*Modifier at XX*/class MyInner {}

}

What modifiers would be legal at XX in the above code?

A. public

B. private

C. static

D. friend

正确答案:ABc

 

595. Given the following code how could you invoke the Base constructor that will print out the string "base constructor";

class Base{

System.out.println("base constructor");

}

Base(){

}

}

public class Sup extends Base{

public static void main(String argv[]){

Sup s=new Sup();

//One

}

Sup(){

//Two

}

public void derived(){

//Three

}

}

Select the right answer.

A. On the line After //One put Base(10);

B. On the line After //One put super(10);

C. On the line After //Two put super(10);

D. On the line After //Three put super(10);

正确答案:C

 

596. What will happen when you attempt to compile and run the following code?

class Base{

private void amethod(int iBase){

System.out.println("Base.amethod");

}

}

class Over extends Base{

public static void main(String argv[]){

Over o=new Over();

int iBase=0;

o.amethod(Base);

}

public void amethod(int iOver){

System.out.println("Over.amethod");

}

}

Select the right answer.

A. Compile time error complaining that Base.amethod is private

B. Runtime error complaining that Base.amethod is private

C. Output of "Base.amethod"

D. Output of "Over.amethod"

正确答案:D

 

597. For a class defined inside a method, what rule governs access to the variables of the enclosing method?

A. The class can access any variable

B. The class can only access static variables

C. The class can only access transient variables

D. The class can only access final variables

正确答案:D

 

598. What will happen when you attempt to compile and run the following code?

import java.io.*;

class Base{

public static void amethod()

throws FileNotFoundException{}

}

public class ExcepDemo extends Base{

public static void main(String argv[]){

ExcepDemo e=new ExcepDemo();

}

public static void amethod(){}

protected ExcepDemo(){

try{

DataInputStream din=

new DataInputStream(System,in);

System.out.println("Pausing");

din readChar();

System.out.println("Continuing");

This.amethod();

}catch(IOException ioe){}

}

}

Select the one right answer.

A. Compile time error caused by protected constructor

B. Compile time error caused by amethod not declaring Exception

C. Runtime error caused by amethod not declaring Exception

D. Compile and run with output of "Pausing" and" Continuing" after a key is hit

正确答案:D

 

599. What will happen when you attempt to compile and run this program?

public class Outer{

public String name="Outer";

public static void main(String argv[]){

Inner i=new Inner();

i.showName();

}

//End of main

private class Inner{

String name=new String("Inner");

void showName(){

System.out.println(name);

}

}//End of Inner class

}

Select the one right answer.

A. Compile and run with output of "Outer"

B. Compile and run with output of "Inner"

C. Compile time error because Inner is declared as private

D. Compile time error because of the line creating the instance of lnner

正确答案:D

 

600. Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child classes. One is called LinuxPC and one is called WindowsPC.

The main difference between the two is that one runs the Linux operating System and the other runs the Windows System(of course another difference is that one needs constant re-booting and the other runs reliably),Under the WindowsPC are twp Sub classes one called Server and one Called Workstation. How might you appraise your designers work?

A. Give the go-ahead for further design using the current scheme

B. Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type

C. Ask for the option of WindowsPC to be removed as it will soon be obsolete

D. Change the hierarchy to remove the need for the superfluous Computer Class

正确答案:B

 

601. Which of the following statements are true?

A. An inner class may be defined as static

B. There are No circumstances where an inner class may be defined as private

C. An anonymous class may have only one constructor

D. An inner class may extend another class

正确答案:AD

 

602. Given the following class definition, which of the following methods could be legally placed after the comment?

public class Rid{

public void amethod(int j,String s){}

//Here

}

Select the one right answer.

A. public void amethod(String s,int i){}

B. public int amethod(int i,String s){}

C. public void amethod(int i,String mystring s){}

D. public void Amethod(int i,String s){}

正确答案: AD

 

603. Given the following class definition which of the following can be legally placed after the comment line?

class Base{

public Base(int i){}

}

public class MyOver extends Base{

public static void main(String arg[]){

MyOver m=new MyOver(10);

}

MyOver(int i){

super(i);

}

MyOver(String s,int i){

this(i);

//Here

}

}

Select the one right answer.

A. MyOver m=new MyOver();

B. super();

C. this("Hello",10);

D. Base b=new Base(10);

正确答案: D

 

604. Given the following class definition which of the following statements would be legal after the comment?

class InOut{

String s=new String("Between");

public void amethod(final int iArgs){

int iam;

class Bicycle{

public void sayHello(){

//Here

}//End of bicycle class

}

}//End of amethod

public void another(){

int iOther;

}

}

Selec the one right answer.

A. System.out.println(s);

B. System.out.println(Other);

C. System.out.println(iam);

D. System.out.println(Args);

正确答案: AD

 

605. Which of the following statements are true?

A. An interface can only contain method and not variables

B. Interfaces cannot have constructors

C. A class may extend only one other class and implement only one interface

D. Interfaces are the Java approach to addressing its lack of multiple inheritance, but require implementing classes the functionality of the Interfaces

正确答案: BD

 

606. What will happen when you attempt to compile and run the following code?

class Base{

public void Base(){

System.out.println("Base");

}

}

public class In extends Base{

public static void main(String argv[]){

In i=new In();

}

}

Select the one right answer.

A. Compile time error Base is a keyword

B. Compile and no output at runtime

C. Output of Base

D. Runtime error Base has no valid constructor

正确答案: B

 

607. Which of the following statements are true?

A. Constructors cannot have a visibility modifier

B. Constructors can be marked public and protected, but not private

C. Constructors can only have a primitive return type

D. Constructors are not inherited

正确答案: D

 

608. What will happen when you attempt to compile and run the following code?

class Base{

Base(int i){

System.out.println("Base");

}

}

class Severn extends Base{

public static void main(String argv[]){

Severn s=new Severn();

}

void Severn(){

System.out.printl("Severn");

}

}

Select the one right answer.

A. Compilation and output of the string "Severn" at runtime

B. Compile time error

C. Compilation and no output at runtime

D. Compilation and output of the string "Base"

正确答案: B

 

609. Which of the following statements are true?

A. The default constructor has a return type of void

B. The default constructor takes a parameters of void

C. The default constructor takes no parameters

D. The default constructor is not created if the class has any constructors of its own

正确答案: CD

 

610. Which of the following statements statement are true?

A. All of the variables in an interface are implicitly static

B. All of the variables in an interface are implicitly final

C. All of the methods in an interface are implicitly abstract

D. A method in an interface can access class level variables

正确答案: ABC

 

 

数据结构基础系列(9):排序

数据结构课程是计算机类专业的专业基础课程,在IT人才培养中,起着重要的作用。课程按照大学计算机类专业课程大纲的要求,安排教学内容,满足需要系统学习数据结构的人。系列课程包含11个部分,本课为第9部分排序,介绍插入排序、交换排序、选择排序、归并排序、基数排序等各种排序算法,以及各种算法的性能分析。
  • 2015年11月25日 22:02

最新SCJP考题资料

  • 2009年06月18日 20:51
  • 4.53MB
  • 下载

SCJP考题1.doc

  • 2009年08月02日 22:44
  • 647KB
  • 下载

scjp 考题回忆

  • 2008年03月16日 17:01
  • 108KB
  • 下载

SCJP考题_学习笔记

  • 2007年08月07日 16:40
  • 203KB
  • 下载

SCJP310-055

  • 2008年03月20日 11:38
  • 2.23MB
  • 下载

SCJP最全面最经典考题

  • 2009年07月30日 21:00
  • 5.91MB
  • 下载

SCJP学习指南完整版pdf共18章

  • 2008年07月21日 23:18
  • 13MB
  • 下载

SCJP考题

  • 2007年08月13日 00:17
  • 104KB
  • 下载

SCJP考试85%通过,说一下感悟。

说起考试的起因就要先谢一个人,她就是我女朋友。怎么说呢?这个学期到了最后其实是穷困潦倒,欠了别人钱不说,连吃饭都有问题了,最后不是她可能都饿死街头了。学校 软件中心做活动说是原价1250的考试费,现在...
  • bakiya
  • bakiya
  • 2006-07-20 12:26:00
  • 2278
收藏助手
不良信息举报
您举报文章:SCJP考题9
举报原因:
原因补充:

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