SCJP试题十一

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

正确答案:A、D

 

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);

正确答案:C、D

 

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

正确答案:C、D

 

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

正确答案:A、C

 

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;

}

}

正确答案:B、D

 

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

正确答案:A、B、D

 

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

正确答案:A、B、C

 

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;

}

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

}

}

正确答案:A、E

 

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 to String(){

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 to String(){

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

23)}

24)

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

26)Exsuper a=new Exsuper("First","1^sd")

27)Exsuper b=new Example("second","2^sd")

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 Second a.k.a 2^nd

E. The following output:

   a is First a.k.a 1^st

   b is Second a.k.a 2^nd

正确答案: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. Mehtods 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 cirectly,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 definedin B

D. the variable z defined in D

正确答案:A、B、C

 

586. Given this interface definition:

interface A{

int method1(int i);

int method2(int j);

}

Which of the following classes implements A

A.class B{

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

}

正确答案:C、E

 

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

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 runs 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 ouer class
B. Class A attempts to creatc an instance of B when there is no current instance of class A.

C.

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

 

override    overload

591. Which of the following statements are true?

A. Methods cannot be overriden to be more private

B. Static methods cannot be overloaded

C. Private methods cannot be overloaded

D. An overloaded method cannot throw exceptions vot 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 Base{

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 {}

正确答案:B、C

 

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

正确答案:A、B、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.anethod");

}

}

class Over extends Base{

public static void main(String argv[]){

Over o=new Over();

int iBase=0;

o.amethod(iBase);

}

public void amethod(int iOver){

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

}

}

Select the right answer.

A. Compile time error complaning that Base.amethod is privste

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 gorerns 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 readChE();

System.out.println("Continuing");

this amethod();

}catch(IOException ioe){}

}

}

Select the one right answer.

A. Compile time error carsed by protected constructor

B. Compile time error carsed by amethod not declaring Exception

C. Runtime error caused by amethod not declaring Exception

D. Comile 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 teght 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

 

 

第八周测试 61题

 

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 two Sub classes one called Server and one Called Workstation.How might you appraise your desigmers work?

A. Give the goahead for further design using the curremt 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 onsolete

D. Change the hierarchy to remove the need for the superfluous(多余的,过剩的) Conputer 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

正确答案:A、D

 

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

public classRid{

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){}

正确答案: A、D

 

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 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);

正确答案: A、D

 

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 reqrire inplementing classes the functionality of the Interfaces

正确答案: B、D

 

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 private return type

D. Constructors are not inherited          可重载不可继承

正确答案: D

 

608. What will happtn when you attempt tp 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.println("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 putout 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 return type 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

正确答案: C、D

 

610. Which of the following statements statements 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 sbstract

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

正确答案: A、B、C

 

611. Which of the following statements are true?

A. A method in an interface must not have a body

B. A class may extend one other class plus at most one interface
C. A class may extend at most one other class plus implement many interfaces

D. An class accesses an interface via the diyword uses

正确答案: A、C

 

 

612. You are given a class hierarchy(层次) with an instance of the class Dog.The class Dog is a child of mammal(哺乳动物) and the class Mammal is a child of the class Vertebrate.The class Vertebrate has a method called move which prints out the string "move".The class mammal overrides this method and prints out the string "walks".The class Dog overrides this method and prints out the string"walks on paws".Given an instance of the class Dog.how can you access the ancestor method move in Vertebrate so it prints out the string"move".

A. d.super().super().move();

B. d.parent().parent().move();

C. d.move();

D. none of the above;

正确答案: D

 

613. Which of the following most closely describes the process of overriding?

A. A class with the same name replaces the functionality of a class defined earlier in the hierarchy

B. A method with the same name completely replaces the functionality of a method earlier in the hierarchy

C. A method with the same name but different parameters gives multiple uses for the same method name

D. A class is prevented from accessing methods in its immediate ancestor

正确答案: B

 

614. Given the following class definition:

public class Upton{

public static void amethod(int i){

}

public void amethod(int i){

}

//Here

}

Which of the following would be legal to place after the comment?

A. public int amethod(int z){}

B. public int amethod(int i,int j){returm 99;}

C. protected void amethod(long 1){}

D. private void anothermethod(){}

正确答案: B、C、D

 

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?ar

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 compile without error

正确答案: D

 

616. Which of the following statements are true?

A. constructors cannot be overloaded

B. constructors cannot be overloaden

C. a constructor can return a primitive or an object trference
D. constructor code executes from the current class up the hierarchy to the ancestor class

正确答案: B

 

617. Which of the following statements are true?

A. A method cannot be overloaded tp be less public in a child class

B. To be overridden a method must have the same name and parameter types

C. To be overridden a method nust have the same name,parameter and return types

D. An overridden method nust ahve the same name,parameter names and parameter types

正确答案: C

 

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

class Base{

Base(){

System.out.println("Base");

}

}

public class Checket extends Base{

public static void main(String argv[]){

Checket c=new Checket();

super();

}

Checket(){

System.out.println("Checket");

}

}

Select the one right answer.

A. Compile time error

B. Checket followed by Checket

C. Base followed by Checket

D. runtime error

正确答案: A

 

619. Which of the following statements are true?

A. Static methods cannot be overriden to be non static

B. Static methods cannot be declared as private

C. Private methods cannot be overloaded

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

正确答案: A

 

620. What is the result when you compile and run the following code?

class Top{

static void myTop(){

System.out.println("Testing myTop method in Topclass");

}

}

public class Down extends Top{

void myTop(){

System.out.println("Testing myTop method in Down class");

}

public static viod main(String[]args){

Top t=new Down();

t.myTop();

}

}

Select the one right answer.

A. Compile Time error

B. Runtime errorPrints Testing myTop method in Top class on the console

C. Prints Testing myTo[ method in Top class on the console

D. Prints Testing myTop method in Down class on the screen

正确答案: A

 

621. At what point the following code shows compile time error?

class A{

A(){

System.out.println("Class A constructor");

}

}

class B extends A{

B(){

System.out.println("Class B constructor");

}

}

public class C extends A{

C(){

System.out.println("Class C constructor");

}

public static void main(String args[]){

A a=new A();//Line 1

A a1=new B();//Line 2

A a2=new C();//Line 3

B b=new C();//Line 4

}

}

Select the one right answer.

A. A a=new A();//Line 1

B. A a1=new B();//Line 2

C. A a2=new C();//Line 3

D. A b=new C();//Line 4

正确答案: D

 

622. Select all correct answers about what is the definition of an interface.

A. It is a blue print

B. A new data type

C. Nothing but a class definition

D. To provide multiple inheritance

正确答案: A、B、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 constrRuntime error A a2=new C();//Line 3

C. Runtime error

D. Compile time error

正确答案: D

 

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

import java.io.*;

class A{

A(){

System.out.println("Executing class A construclor");

}

A(int a)throws Exception{

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

throw new IOException();

}

}

public class B extends A{

B(){

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

}

public static vild main(String args[]){

try{A a=new B();

}catch (Exception e){

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

}

}

}

Select the one right answer.

A. Executing class A constructor followed by Executing class B constructor

B. No output

C. Runtime error

D. Compile time error

正确答案: A

 

625. If you save and compile the following code.it gives compile time error.How do you correct the compile time error?

public class OuterClass{

finsl String s="Iam outer class member variable";

public void Method(){

String s1="Iam inner class variable";

class InnerClass{

Public viod innerMethod(){

int xyz=20;

System.out.println(s);

System.out.println("Integer value is"+ xyz);

System.out.println(s1);//Illegal.compiler error

}

}

}

}

Select the one right answer.

A. By making s1 as static variable

B. By making s1 as public variable

C. By making s1 as final variable

D. By making InnerClass as static

正确答案: C

 

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 thaat inner classes can be defined inside any method

C. This is convention adopted by Sun,to insure that there ix no ambiguity between packages and inner classes.

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

正确答案: C

 

627. What will be printed when you execute the code?

class A{

A(){

System.out.println("Class A Constructor");

}

}

public class B exlends A{

B(){

System.out.println("Class B Constructor");

}

public statie void main(String args[]){

B b=new B();

}

}

Select the one right answer.

A. Class A Constructow followed by Class B Constructor

B. Class B Constructow followed by Class B Constructor

C. Compile time error

D. Run time error

正确答案: A

 

628. Given the piece of code,select the correct to replace at the comment line.

class A{

A(int i){

}

}

public class B extends A{

B(){

//xxxxx

}

public static void main(String args[]){

B b=new B();

}

}

Select the one right answer.

A. super(100);

B. this(100);

C. super();

D. this();

正确答案: A

 

629. Examine the code below and select the best answer.

class OuterOne{

static classInerOne{}

}

A. we can't make instantce of innerclass outside class OuterOne

B. InnerOne in=new Inner()' will make instance of inner class in another class

C. OuterOne.InnerOne in=new OuterOne.Inner()

D. InnerOne in=new OuterOne().new Inner()'will make instance of inner class in another class

正确答案: C

 

630. Which of the statements are true?

A. Overridden methods have the asme method name and signature

B. Overridded methods have the asme method name and signature

C. Overridden methods have the asme method name and different signature

D. Overridded methods have the asme method name and different signature

正确答案: A、D

 

631. What is the result of compiling the following code?

import java.io.*;

classMyExp {

void MyMethod() throws IOException,EOFException{

//............//

}

}

class MyExp1 extends MyExp{

void MyMethod(){

//............//

}

}

public class MyExp2 extends MyExp1{

voik MyMethod() throws IOException {

//............//

}

}

Select the one right answer.

A. Compile time error

B. No compile time error

C. Run-Time error

D. MyMethod() cannot declare IOExceptio in MyExp2 class

正确答案: A、D

 

632. Select the correct anonymous inner class declaration?

A. new Outer.new Inner

B. new Inner() {}

C. new Inner()

D. Outwe.new Inner()

正确答案: B

 

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 stati fields of the enclosing class.

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

正确答案: A、D

 

634. How can you implement encapsulation?

A. By making methods private and variable private.

B. By making methods are public and variables as private.

C. Make all variable are public and access them using methods.

D. Making all methods and variables as protected.

正确答案: B

 

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

public class Test{

public void anethod(int i,String s){}

//Here

}

Select the one right answer.

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

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

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

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

正确答案: A、D

 

636. 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 Derived extends Base{

public static void main(String arg[]){

Derived d=new Derived(10);

}

Derived(int i){

super(i);

}

Derived(String s,int i){

this(i);

//Here

}

}

Select the one right answer.

A. Derived d=new Derived();

B. super();

C. this("Hello",10);

D. Base b=new Base(10);

正确答案: D

 

637. Given the following code fragment:

1) public void create(){

2) Vector mVect;

3) myVect=new Vector();

4)}

Which og the following statements are true?

A. The declaration on line 2 does not allocate memory space for the variable myVect.

B. The declaration on line 2 allocates memory space for a reference to a Vector object.

C. The statement on line 2 creates an object of class Vctor.

D. The statement on line 3 creates an object of class Vctor.

E. The statement on line 3 allocates memory space for an object of class Vector.

正确答案: A、D、E

 

638. Which statements about inheritance are true?

A. In Java programming language only allows single inheritance.

B. In Java programming language allows a class to implement only one interface.

C. In Java programming language a class cannot extend a class and implement a interface together.

D. In Java programming language single inheritance makes code more reliable.

正确答案:A、D

 

639. Given the following code:

1) class Person{

2) public void printValue(inti int j){/*...*/}

3) public void printValue(inti i){/*...*/}

4) }

5) puvlic class Teacher extends Person{

6) public void prinValue(){/*...*/}

7) public void prinValue(int i){/*...*/}

8) public static void main(String args[]){}

9) person t=new Teacher();

10)t.trintValue(10);

11)}

12)}

Which method will the statement on line 10 call?

A. on line 2

B. on line 3

C. on line 6

D. on line 7

正确答案:D

 

640. Given the uncompleted code of a class:

class Person {

String name,department;

int age;

public Person(String n){

name=n; }

public Person(String n, int a){

name=n;

age=a;

}

public Person(String n, String d,int a){

//doing the same as two arguments version of constructor

//including assignment name=n,age=a

department=d;

}

}

Which expression can be added at the "doing the same as..." part of the constructor?

A. person(n,a);

B. this(Person(n,a));

C. this(n,a);

D. this(name,age).

正确答案:C

 

641. Given the following code:

public class Parent {

public int addValue(int a,int b){

int s;

s=a+b;

return s;

}

}

class Child extends Parent{

}

Which methods can be added into class Child?

A. int addValue(int a,int b){// do something...}

B. public void addValue(){//do something...}

C. public int addValue(int a){//do something...}

D. public int addValue(int a,int b)throws MyException {//do something...}

正确答案:B、C

 

642. Given the following code:

public class Parent {

int change(){...}

}

class Child extends Parent{

}

Which methods can be added into class Child?

A. public int change(){}

B. int chang(int i){}

C. private int change(){}

D. abstract int chang(){}

正确答案:A、B

 

643. Given the following code:

class Parent {

String one,two;

public Parent(String a,String b){

one = a;

two = b;

}

public void print(){

System.out.println(one);

}

}

public class Child extends Parent{

public Child(String a,String b){

super(a,b);

}

public void print(){

System.out.println(one+"to"+two);

}

public static void main(String arg[]){

Parent p=new Parent("south","north");

Patent t=new Child("east","west");

p.print();

t.print();

}

}

Which of the following is correct?

A. Cause error during compilation.

B. south

east

C. south to north

east to west

D. sorth to north

east

E. south

east to west

正确答案:E

 

644. Given the following code:

class Person{

String name.department;

public void printValue(){

System.out.println("name is "+name);

System.out.println("department is"+depqrtment);

}

}

public classnTeacher extendsb Person{

int salary;

public class Teacher extends Person{

int salary;

public void prinValue(){

//doing the same as in the parent method printValue()

//including print the value of name and department.

System.out.println("salary is"+salary);

}

}

Which expression can be added at the "doing the same as..."part of the method printValue()?

A. printValue();

B. this.printValue();

C. person.printValue();

D. super.printValue();

正确答案:D

 

645. Given the following code:

1) public class Test{

2) int m,n;

3) public Test(){}

4) public Test(int a){m=a;}

5) public static void main(String arg[]){

6) Test t1,t2;}

7) int j,k;

8) j=0;k=0;

9) t1=new Testz();

10)t2=new Test(j,k);

11)}

12)}

Which line would cause one error during compilation?

A. line 3

B. line 5

C. line 6

D. line 10

正确答案:D

 

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

 

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

 

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

 

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

1: public class Test

2: {

3: int maxExements;

4:

5: void Test()

6: {

7: maxElements=100;

8: System.out.println(maxElements);

9: }

10:

11:Test(int i)

12:{

13:maxElements=i;

14:System.out.println(maxElements);

15:}

16:

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

18:{

19:Test a=new Test();

20:Test b=new Test(999);

21:}

22:}

Select the one right answer.

A. prints 100 and 999.

B. prints 999 and 100.

C. Compilation error at lie 3, variable maxElements was not initialized.

D. Compillation error at line 19.

正确答案:D

 

651. Which two demonstrate a "has a"relationship?(Choose two)?

A. public interface Person { }

public class Employee extends person{ }

B. public interface Shape { }

public interface Rectandle extends Shape{ }

C. public interface Colorable{ }

public class Shape implements Colorable{ }

D. public class Species{ }

public class Animal{private Species species;}

E. interface Component{}

class Container implements Component{

private Component[]children;

}

正确答案:D、E

 

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 method(){

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

 

654. What will be the result of compiling the following code?

public class Test{

static int age;

public static void main(String args[]){

age=age+1;

System.out.println("The age is"+age);

}

}

Select the most appropriate answer.

A. Compiles and runs with no output

B. Compiles and runs printing out The age is 1

C. Compiles but generates a runtime error

D. Does not compile

E. Compiles but generates a compile time error

正确答案:B

 

655. What is the correct declaration of an abstract method that is intended to be public?

Select the most appropriate answer.

A. public abstract void add();

B. public abstract void add() {}

C. public abstract add() {}

D. public virtual add();

正确答案:A

 

656. Under what situations do you obtain a default constructor?

Select the most appropriate answer.

A. When you define any class;

B. When the class has no other constructors;

C. When you define at least one constructor;

正确答案:B

 

657. Given the following code:

public the most appropriate answer.

A. public void Test() {...}

B. public Test(){...}

C. public static Test(){...}

D. public static void Test(){...}

正确答案:B

 

658. Which of the following is a legal return type of a method overloading the following method?

public void add(int a){...}

Select the most appropriate answer.

A. void

B. int

C. Can be anything

正确答案: C

 

659. Which of the following statemints is correct for a method which is overriding the following method?

public void add(int a){...}

Select the most appropriate answer.

A. the overriding method must return void

B. the overriding method must return int

C. the overriding method can return whatever it likes

正确答案: A

 

660. Given the following classes defined in separate files?

class Vehicte {

public void dreve(){

System.out.priantln("Vebile.drive");

}

}

class Car extends Vahicle{

public void drive(){

System.out.println("Car.drive")

}

}

public class Test{

public static void main(String args[]){

Vehicle v;

Car c;

v=new Vehicle();

c=new Car();

v.drive();

c.drive();

v=c;

v.drive();

v.drivez();

}

}

What will be the effect of compiling and running this class Test?

Select the most appropriate answer.

A. Generates a Compiler error on the statement v=c;

B. Generates runtime error on the statement v=c;

C. Prints out:

Vehicle:drive

Car:drive

D. Prints out:

Vehicte:drive

Car:drive

Vehicle:drive

正确答案: C

 

 

第八周测试600-660

 

661. Where in a constructor,can you place a call to a constructor defined in the super class?

Select the most appropriate answer.

A. Anywhere

B. The first statement in the constructor

C. The last statement in the constructor

D. You can't call super in a constructor

正确答案: B

 

662. Which variables can an inner class access from the class which encapsulates it?

Select all correct answers.

A. All static variables

B. All final variables

C. All instance variables

D. Only final instance variables

E. Only final static variables

正确答案: A、B、C

 

663. What class must an inner class extend?

Select the most appropriate answer

A. The top level class

B. The Object class

C. Any class or interface

D. It must extend an interface

正确答案: C

 

664. Consider the following exanple:

class Firs{

public First(String s){

System.out.println(s);

}

}

public class Second extends First{

public static void main(String args[]){

new Second();

}

}

What os the result of compiling and running the Second class?

Select the most appropriate answer.

A. Nothing happens

B. A string is printed to the standard out

C. An instance of the class First is generated

D. An instance of the class Second is created

E. An exception is raised at runtime stating that there is no null parament constructor class First.

F. The class second will not compile as there is no null parameter constructor in the class First.

正确答案: F

 

665. Consider the following classes:

public class Test{

public static void test(){

this print();

}

puvlic static void print(){

System.out.println("Test");

}

public static void main(String args[]){

test();

}

}

What is the result of compiling and running this class?

Select all correct answer.

A. The string Test is printed to the standard out.

B. A runting exceptinon is ralsed stating that an object has not been created.

C. Nothing is printed to the standard output.

D. An exception is raised stating that the method test cannot be found.

E. An exception is raised stating that the variable this can only be used within an instance.

F. The class fails to compile stating that the variable this is undefined.

正确答案: F

 

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.

正确答案: C

 

667. Exanine the following code which includes an inner slass:

public final class Test{

class Inner{

void test(){

if(Test.this.flag);{

sample);{

sample();

}

}

}

private boolean flag=false;

public void sample(){

System.out.println("Sample");

}

public Test(){

(new Inner());test();

}

public static void main(String args[]){

new Test();

}

}

Select the most appropriate answer.

A. Prints out "Sample"

B. Prints produces no output but terminates correctly.

C. Program does not terminate.

D. The program will not compile

正确答案: A

 

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"

正确答案: D

 

669. Given the following code:

class Outer{

   class Inner{

   }

}

How will you create an instanceof Inner Class out side? Select 2

A.Inner a =newInner();

B.Outer o=new Outer();Inner a=new o.Inner();

C.Outero=new Outer();Outer.Inner a=new o.inner();

D.Outer.Inner a=new Outer().newInner();

正确答案: C D

 

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.上述答案都不对

正确答案: D

 

671. Given the following code:

        class Super{

           int i=0

           Super(String s){

               i=10

            }

}

class Sub extends Super{

   Sub(String s){

       i=20;

   }

  public static void main(String args[]){

      Sub b=new Sub("hello");

      System.out.printIn(i);

What will be the value of i?

A.Compilation Error

B.Runtime Error

C.0

D.10

E.20

正确答案:E

 

672. Where will be a 'is a' relationship will occur select one?

 

A. interface Person

   class Employee implements Person

B. interface Shape

   interface Rectangle extends Shape

C. interface Component

   class Objects implement Component{

   Component[]Component;

   }

正确答案: B

 

673.which are the correct forms of Constructors for the class hai?

A. public void hai(int a)

B. hai(int a,int b)

C. public hai(int a)

D. int hai(int c, int d)

E. int hai()

F. int hai(String s)

正确答案: B C

 

674. Which are the correct forms of overriding for the method void hai(int a,int b)?

A.public void hai(int a,int b)

B.protected void hai(int a,int b)

C.public hai(int a)

D.int hai(int c,int d)

E.int Hai()

F.int hai(String s)

正确答案: A B

 

675. Given the following code:

      1.interface foo

      2.{

      3.int I=0;

      4.}

      5.class sreejith implements foo

      6.{

      7.public static void main(String args[])

      8.{sreejith s=new sreejith();

      9.int j=0;

      10.j=s.I;

      11.j=sreejith.I;

      12.j=foo.i;

      13.s.I=2;

}

}

 

where will compilation fail?

 

A.10

B.11

C.12

D.13

E.No error

正确答案:D

 

676.What is the modifier is used to make a method to be overridden in subclass?

A. final

B. abstract

C. static

D.volatile

正确答案:B

 

677. Giventhe following code:

      public class Outer{

        //

      }

What should be inserted at / so that the code will compile fine?

 A.private class Inner{

       static int k;

   }

 B. static class Inner{

        static int k;

    }

 C.public class Inner{

     static int k;

   }

 D.public abstract class Inner{

     public abstract void method();

   }

正确答案:B D

 

678.Which of the following are true about encapsulation?

A.direct access to variables.

B.Access to variables through methods.

C.keeping methods protected.

D.use methods access and modify the variable data.

正确答案:B 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"

正确答案: A

 

680. What is true about consturctors?

A.They initialize all the member variables

B.They initialize all the instance variables

C.If there is no constructor.the compiler includes default constructor.

D.Compiler supplied constructor will invoke the default constructor of the super class.

正确答案: C D

 

681. Which of the following will describe a perfect ecapsulation?(封装)

A.making all method private

B.making all variables private

C.making class final

D.making methods to public

E.making all variables private and access it through methods

正确答案:B E

 

682. Given the following code:

     Public class base{

        String name;

        String value;

        public base( string n,String m){

           name=n;

           value=m;

     }

     public String to String(){

         return name;

     }

}

     public class sub extends base{

       public String to String(){

            return name+":"+value;

     }

     public sub(String n, String m){

        super(n,m);

     }

     public static void main(Stromgargs[]){

        base b=new base("first","1st");

        base b1=new sub ("second","2nd"),

        System.out.println(b.toString()+bl.toString());

      }

}

What will be the output?

A.compilation error

B.first second:2nd

C.Second:2second:2nd

正确答案:B

 

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

正确答案:C

 

684. What will you write in the palce of 'xxx'to make instantce of inner class?

class OuterOne{

class InnerONe {}

}

class Test{

OuterOne o=new OuterOne();

//write code to create an instance of the inner class

}

Selct all of the right answers from the flowing.

A. o.InnerOne in=o.new InnerOne();

B. InnerOne in=new o.new InnerOne();

C. OuterOne.InnerOne in =new o. InnerOne();

D. OuterOne.InnerOne in =o.nwe InnerOne();

正确答案: Runnable


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wangjun_pfc/archive/2007/10/13/1823214.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值