2024年3月28日发(作者:)

初级部分阶段测试卷

选择题

1)在Java类中,使用以下()声明语句来定义公有的int型常量MAX。

A. public int MAX = 100;

B. final int MAX = 100;

C. public static int MAX = 100;

D. public static final int MAX = 100;

2)给定Java代码如下所示,在横线处新增下列()方法,是对cal方法的重载。(选二项)

public class Test{

public void cal(int x, int y, int z) {}

}

A. public int cal(int x, int y, float z){ return 0; }

B. public int cal(int x, int y, int z){ return 0; }

C. public void cal(int x, int z){ }

D. public void cal(int z, int y, int x){ }

3)下面Java代码的运行结果是()。

class Penguin {

private String name=null; // 名字

private int health=0; // 健康值

private String sex=null; // 性别

public void Penguin() {

health = 10;

sex = "雄";

n("执行构造方法。");

}

public void print() {

n("企鹅的名字是" + name +

",健康值是" + health + ",性别是" + sex+ "。");

}

public static void main(String[] args) {

Penguin pgn = new Penguin();

();

}

}

A.企鹅的名字是null,健康值是10,性别是雄。

B.执行构造方法。

企鹅的名字是null,健康值是0,性别是null。

.

C.企鹅的名字是null,健康值是0,性别是null。

D.执行构造方法。

企鹅的名字是null,健康值是10,性别是雄。

4)在Java中,以下程序编译运行后的输出结果为()。

public class Test {

int x, y;

Test(int x, int y) {

this.x = x;

this.y = y;

}

public static void main(String[] args) {

Test pt1, pt2;

pt1 = new Test(3, 3);

pt2 = new Test(4, 4);

(pt1.x + pt2.x);

}

}

A. 6

B. 3 4

C. 8

D. 7

5) Java中,如果类C是类B的子类,类B是类A的子类,那么下面描述正确的是()。

A. C不仅继承了B中的公有成员,同样也继承了A中的公有成员

B. C只继承了B中的成员

C. C只继承了A中的成员

D. C不能继承A或B中的成员

6)给定如下一个Java源文件,编译并运行,以下结果正确的是()。

class Parent1 {

Parent1(String s){

n(s);

}

}

class Parent2 extends Parent1{

Parent2(){

n("parent2");

}

}

public class Child extends Parent2 {

public static void main(String[] args) {

Child child = new Child();

}

.

}

A.编译错误:没有找到构造器Child()

B.编译错误:没有找到构造器Parent1()

7)以下关于Object类说法错误的是()。

A.一切类都直接或间接继承自Object类

C.正确运行,没有输出值

D.正确运行,输出结果为:parent2

B.接口亦继承Object类

C. Object类中定义了toString()方法

D. Object类在包中

8)给定Java代码如下所示,则编译运行后,输出结果是()。

class Parent {

public void count() {

n(10%3);

}

}

public class Child extends Parent{

public void count() {

n(10/3);

}

public static void main(String args[]) {

Parent p = new Child();

();

}

}

A. 1

B. 1.0

C. 3

9)编译运行如下Java代码,输出结果是()。

class Base {

public void method(){

}

.

D. 3.3333333333333335

("Base method");

}

class Child extends Base{

public void methodB(){

("Child methodB");

}

}

class Sample {

}

public static void main(String[] args) {

Base base= new Child();

B();

}

A. Base method

B. Child methodB

C. Base method Child MethodB

D.编译错误

10) 给定如下Java程序代码,在横线处加入()语句,可以使这段代码编译通过。(选二项)

interface Parent{

public int count(int i);

}

public class Test implements Parent {

public int count(int i){

return i % 9;

}

public static void main(String[] args){

________________

int i = (20);

}

}

A. Test p = new Test();

B. Parent p = new Test();

C. Parent p = new Parent();

D. Test p = new Parent();

11.

import .*;

public class TestListSet{

public static void main(String args[]){

List list = new ArrayList();

(“Hello”);

(“Learn”);

.