SCJP考题5

来源:互联网 发布:淘宝创业综合 编辑:程序博客网 时间:2024/05/21 10:48

第八周测试 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 top 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 classRid{

public void amethod(int i, 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(

正确答案: D

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

正确答案: 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 reqrire inplementing classes the functionality of the Interfaces

正确答案: BD

 

606. W@hat will gappen 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();

}

}

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. Comstructors cannot have a visibility modifier

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

C. Comstructors can only have a prinitive return type

D. Comstructors 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.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 putput 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

正确答案: CD

 

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

正确答案: ABC

 

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

正确答案: AC

 

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 thd class Vertebrate.The class Vertebrate has a method called move which prints out the string "move".The class mammal onerrides 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().supeer().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 wigh the same name but different parameters gives multiple uses for the same method name

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

正确答案: B

 

614. Given the following class definition:

public dalss Upton{

public static void amethod(int i){

}

oublic void amethod(int i){

}

//Here

}

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

A. public int amethod(int z){}

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

C. orotected void amethod(long 1){}

D. private void anothermethod(){}

正确答案: BCD

 

615. Given the following class definition:

public class Droitwich{

classone {

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 not 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 orerloaded 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[]){

hecket c=new Checket();

srper();

}

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

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 ooint 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

正确答案: ABD

 

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

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

}

}

}

Select the one right answer.

A. Executing class A constructor

B. Executing class B constrRuntime errorA 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

正确答案: AD

 

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

正确答案: AD

 

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.

正确答案: AD

 

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

正确答案: AD

 

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.

正确答案: ADE

 

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.

正确答案:AD

 

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

正确答案:BC

 

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

正确答案:AB

 

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;

}

正确答案:DE

 

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

 

 

 
原创粉丝点击