1609第一次月考详细解析

更新时间:2024-03-02 19:23:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1.(单选题)下列数组声明语句中,错误的是:()。 A.int[] arr = new int[]{};

B.int[] arr = new int[];//缺少数组长度 C.int[] arr = {};

D.int[][] arr = new int[2][]; 正确答案:B

2.(单选)class Card{}下列不属于Card类构造方法的是:() A.Card(){} B.public Card(){}

C.public void Card(){}//构造方法没有返回值,但也不能写void D.private Card(){} 正确答案:C

3.(单选)下面不属于Java语言特点的是: A.平台无关 B.面向对象

C.支持指针类型//不是java的特点,是c语言的 D.垃圾回收机制 正确答案:C

4.(单选)下列选项中的类,能正确实现java.lang.Runnable接口和java.lang.Clonable接口的是()。

A.public class Session implements Runnable, Clonable { public void run(); //实现接口,要重写接口的抽象方法

public Object clone(); }

B.public class Session implements Runnable, implements Clonable {//写一个implements即可

public void run() { / do something */ } public Object clone() { / make a copy */ } }

C.public class Session implements Runnable, Clonable { public void run() { / do something */ } public Object clone() { /* make a copy */ } } D.public class Session extends Runnable, Clonable { //接口不是用来继承的 public void run() ; public Object clone(); } 正确答案:C

5.(单选)下列属于不合法Java标识符的是()。

// java 标识符命名规范: 字母、数字、$、_(下划线),不可用数字开头,不能是java 的关键字 A._mem

B.12a//不能以数字开头 C.M12 D.$12 正确答案:B

6.(单选)下列Java标识符,错误的是()

A._sys_varl B.$change C.User_name

D.1_file//不能以数字开头 正确答案:D

7.(单选)Java程序的执行过程中用到一套JDK工具,其中javac.exe是指()。

A.Java语言编译器 B.Java字节码解释器 C.Java文档生成器 D.Java类分解器 正确答案:A

8.(单选)运行下列代码:

int[] oneArr = { 2, 11, 26, 27, 37, 44, 48, 60 }; int[] twoArr = { 19, 35, 49, 55, 58, 75, 83, 84, 91, 93 }; int[] threeArr = new int[oneArr.length + twoArr.length]; int p = 0, q = 0;

while (p < oneArr.length && q < twoArr.length) {

threeArr[p + q] = oneArr[p] < twoArr[q] ? oneArr[p++] : twoArr[q++]; }

if (p < oneArr.length) {

System.arraycopy(oneArr, p, threeArr, p + q, oneArr.length - p); } else if (q < twoArr.length) {

System.arraycopy(twoArr, q, threeArr, p + q, twoArr.length - q); }

System.out.println(Arrays.toString(threeArr)); 输出的结果是:()。 A.[2,11,26,27,37,44,48,60,19,35,49,55,58,75,83,84,91,93]; B.[2,11,19,26,27,35,37,44,48,49,55,58,60,75,83,84,91,93]; C.[19,35,49,55,58,75,83,84,91,93,2,11,26,27,37,44,48,60]; D.[2,19,11,35,26,49,27,55,37,58,44,75,48,83,60,84,91,93]; 正确答案:B

//代码太多了,自己在eclipse运行一下,用debug调试一下,每次数组的变化,其实就是将两个数组按从小到大的顺序合并 9.(单选)A类中有一个方法:

protected int print(String str){},

B类继承A类, 以下方法能在B类中重写A类中print()方法的是: ()。 //考大家重写:

重写原则:两同两小一大

重写要求子类中的返回值类型小于或者等于父类型,有一个特殊情况,如果父类的返回值类型是基本类型或者是void的,子类必须与父类保持一致

A.public int print(String str){} B.private int print(String str){} C.private void print(String str){} D.public void print(String str){} 正确答案:A

10.(单选)下列代码的输出结果是()。 boolean

b=true?false:true==true?false:true; System.out.println(b);

//三目运算符结构:boolean表达式?表达式1:表达式2

true?false:true==true?false:true; 选择表达式1 :false A.true B.false C.null

D.空字符串 正确答案:B

11.(单选)下列赋值语句中,正确的是()。 A.byte b1 = 10, b2 = 20; byte b=b1+b2; //需要强转,byte b = (byte)(b1+b2) B.byte b1 = 10, b2 = 20; byte b=~b1; //需要强转, byte b=(byte)(~b1);

C.byte b1 = 10, b2 = 20; byte b=b1>>1; //需要强转byte b=(byte)(b1>>1); D.byte b1 = 10; byte b=++b1; 正确答案:D

12.(单选)类Super及Sub定义如下: public class Super { private void f() {

System.out.println(\public void g() { f(); }

public void k() { f(); } }

public class Sub extends Super { private void f() {

System.out.println(\

public void k() { f(); } } 运行下列语句: Super obj = new Sub();

//创建了一个obj的引用变量指向Sub对象,类型为Super obj.g();

//能点出来什么看类型,所以这时调的g方法应该是访问Super的g()方法,g方法里调f()方法,父类的f()方法为private为不可重写。

虽然子类中看上去重写了,其实是两个无关f()方法,只是方法名而已。 在多态调用的时候,只会直接找父类的f()方法.

所以调用f()方法时,实际是调用父类的private。输出:Super.f()

obj.k();

//调k()方法,子类重写后的版本,它为一个公共方法,该公共方法再调用本类的私有方法.

输出:Sub.f()

输出的结果是:()。 A.Sub.f() Sub.f() B.Sub.f() Super.f() C.Super.f() Sub.f() D.Super.f() Super.f() 正确答案:C 13.

(单选)关于下列代码说法正确的是: class ClassA {

public int numberOfinstances;

protected ClassA(int numberOfinstances) { this.numberOfinstances = numberOfinstances; } }

public class ExtendedA extends ClassA { private ExtendedA(int numberOfinstances) { super(numberOfinstances); }

public static void main(String[] args) {

ExtendedA ext = new ExtendedA(420); //new对象,走进子类构造方法,执行代码前先调用父类的有参构造方法

System.out.print(ext.numberOfinstances); } } A.运行后,输出420 B.运行时抛出异常

C.编译错误,所有的构造器必须是public的 D.编译错误,构造器不能是private的 正确答案:A

//子类(Sub class)可以继承父类(Super class)的成员变量及成员方法。届时,子类将具有父类的成员

注意补充:java构造方法的修饰符:public,protected,默认,private四种都可以

使用public修饰构造方法,那么所有的类都可以实例化这个类。

使用private修饰构造方法,那么所有的类都不可以实例化使用这个类。 14.

(单选)关于下列代码说法正确的是: public class A { private int counter = 0;

public static int getInstanceCount() { return counter; } public A() { counter++; }

public static void main(String[] args) { A a1 = new A(); A a2 = new A(); A a3 = new A();

System.out.println(A.getInstanceCount()); } } A.该类编译失败 B.输出:1 C.输出:3 D.输出:0 正确答案:A

//在static方法中无法返回非static的变量由于static在调用时没有具体的对象,因此在static

方法中不能对非static成员(对象成员)进行访问。

15.(单选)下面for语句,存在编译错误的是()。 A.for( ; ; ){}//相当于while(true),死循环 B.for(int i=0; i < 100;i++){}

C.for(int i = 0, j=0; ;i++,j++){}//相当于while(true),死循环 D.for(int i = 0; i < 10){}//缺循环变量的变化 正确答案:D 16.

(单选)请看下列代码: interface Foo {

int bar(); }

public class Sprite { public int fubar(Foo foo) { return foo.bar(); } public void testFoo() { fubar( <插入代码> ); } }

使类Sprite编译通过,在<插入代码>处应填入的代码是: A.Foo { public int bar() { return 1; } } B.new Foo { public int bar() { return 1; } } C.new Foo() { public int bar(){return 1; } } D.new class Foo { public int bar() { return 1; } } 正确答案:C

// 接口无法实例化:fubar方法中需要传入一个Foo类型的参数,但是Foo只是一个接口,无法直接实例化对象,

因此在这里我们选择了匿名内部类进行实例化

17.

(单选)请看下列代码: public class Plant { private String name; public Plant(String name) {

this.name = name; }//Plant中的有参的构造方法 public String getName() { return name; } } class Tree extends Plant {

public void growFruit() { } public void dropLeaves() { } } 下列说法正确的是:

A. 在Tree类中添加代码:public Tree() { Plant(); },编译将通过 //子类构造方法中调用父类的构造方法,写法是:super(); 不写的话系统会默认有

B.在Plant类中添加代码:public Plant() { Tree(); },编译将通过 C.在Plant类中添加代码:public Plant() { this(”fern”); },编译将通//无参构造方法中调用有参的构造方法,可以。格子类的时候,有类似的例子

D.在Plant类中添加代码:public Plant() { Plant(”fern”); },编译将通过 正确答案:C 18.

(单选)请看下列代码编译和运行的结果是()。 interface DeclareStuff {

public static final int EASY = 3; void doStuff(int t); }

public class TestDeclare implements DeclareStuff { public static void main(String[] args) { int x = 5;

new TestDeclare().doStuff(++x); }

//调用方法,把++x(为6)传给了形参s,这时s为6 s = 6 + 3 + 7

void doStuff(int s) {//编译错误,方法缺public 修饰,接口的方法默认都是由public abstract 修饰的

s += EASY + ++s; //等同于s = s + EASY + (++s)

//用debug调试,非常容易看到结果的变化

System.out.println(\ A.s=14 B.s=16 C.s=10 D.编译失败

正确答案:D//如果没有编译错误,能输出s=16 19.

(单选)下列关于IDE开发环境Eclipse,说法错误的是:()。 A.Eclipse可以通过插件(plugin)的方式扩展其功能。

B.Eclipse联盟是由IBM公司捐资组建的。 C.Eclipse使用了SWT图形界面技术。 D.Eclipse的运行不需要有JRE的支持。

正确答案:D//这题都要讲解的话,是在侮辱你的智商 20.

(单选)下列代码的输出结果是: public class Blip {

protected int blipvert(int x) { return 0; } } class Vert extends Blip { <插入代码> }

在<插入代码>处填入选项中的代码,使Vert类没有编译错误的是()。 //继承,可以对方法进行重写,两同两小一大原则:

A.public int blipvert(int x) { return 0; }

B.private int blipvert(int x) { return 0; }//权限要比父类大或相等 C.private void blipvert(int x) { return 0; }//权限和返回类型都错了 D.protected long blipvert(int x) { return 0; }//如果返回值是基本类型要

保持一致

正确答案:A 21.

(单选)下列表达式中,可以得到精确结果的是()。 A.double d1 = 3.0 - 2.6; B.double d4 = 2.5 * 1.5; C.double d2 = 30/300;

D.double d3 = 1/2 + 0.5;//1/2是取整,为0,没法得到0.5 正确答案:B 22.

(单选)下列代码的输出结果是()。

public static void main(String[] args) { int[] one=new int[]{4,6,8}; int[] two=new int[]{1,3,5,7,9}; System.arraycopy(one, 1, two, 2, 2); System.out.println(Arrays.toString(two)); } A.[1, 3, 7, 4, 6] B.[1, 3, 5, 7, 8] C.[1, 3, 5, 6, 9] D.[1, 3, 6, 8, 9] 正确答案:D

src:源数组

srcPos:源数组中的起始位置 dest:目标数组

destPos : 目标数组中的起始位置 length:要复制的数组元素的数量

arraycopy(Object src, int srcPos,Object dest, int destPos, int length)

23.

(单选)下列数组声明语句中,错误的是:()。 A.int[] arr = new int[8]; B.int[] arr = new int[8]{}; C.int[] arr = {};

D.int[] arr = new int[]{}; 正确答案:B 24.

(单选)下列代码编译和运行的结果是: public static void main(String[] args) { String[] elements = { \

String first = (elements.length > 0) ? elements[0] : null; true System.out.println(first); } A.编译出错 B.输出:tea C.输出:for D.输出:null 正确答案:C

25.(单选)运行下面的程序:

int a = 100; int b = 200;

a = a + b; //a = 100+200 = 300; b = a - b; //b = 300-200 = 100; a = a - b; //a = 300 – 100 = 200;

Item it = new Item();

it.setDescription(\

//desc = Gobstopper Item it2 = new Item();

it2.setDescription(\

//desc = Fizzylifting

modifyDesc(it, \//desc = Scrumdiddlyumptious

System.out.println(it.getDescription()); System.out.println(it2.getDescription());

//set方法是为对象中的属性赋值;get方法是从对象中获取属性值

A.Scrumdiddlyumptious Scrumdiddlyumptious B.Scrumdiddlyumptious Fizzylifltng C.Gobstopper Scrumdiddlyumptious D.Gobstopper Fizzylifting 正确答案:D

item=new Item();之后更改的变量内存地址不会对外部那个item的地址进行修改,在modifyDesc()自然就不会更改外部那个变量的值。

传递对象一般是引用,即地址,如果在里面重新new了后的变量地址是相当另外一个变量不会影响外面那个变量地址,这样那个内存地址的值就不会被改变了,外面变量地址没改变,指向的仍是开始所指向的对象

39.

(单选)下面的代码用于对数组arr实现冒泡排序: for (int i = 0; i < arr.length - 1; i++) { boolean isSwap = false;

空白处

if (!isSwap) break; }

下列选项中,空白处可以填入的代码是:()。

A.for (int j = arr.length - 1; j > i; j--) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } }

B.for (int j = arr.length - 1; j > 0; j--) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } }

C.for (int j = i + 1; j< arr.length; j++) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } }

D.for (int j = i; j< arr.length; j++) { if (arr[j] < arr[j - 1]) { int temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; isSwap = true; } } 正确答案:A

太恐怖了,这代码,自己放eclipse运行一下吧 40.(单选)请看下列代码: class Payload { private int weight;

public Payload(int wt) { weight = wt; }

public Payload() {}

public void setWeight(int w) { weight = w; }

public String toString() {

return Integer.toString(weight); } } public class TestPayload {

static void changePayload(Payload p) { <插入代码> }

public static void main(String[] args) { Payload p = new Payload();

p.setWeight(1024);weight = 1024 changePayload(p);

把引用的地址传进去,然后再通过调用set的方法改变这个地址指向的对象的内容,把weight值由1024改为420

System.out.println(\//这里直接输出p指向的对象,会自动调用toString的方法 假设运行后输出“The value of p is 420”,那么<插入代码>处应填入代码是:

A.p.setWeight(420); B.Payload.setWeight(420); C.p = new Payload(420);

D.p = new Payload(); p.setWeight(420); 正确答案:A 41.

(单选)下列代码的输出结果是()。

abstract class Vehicle {

public int speed() { return 0; } }

class Car extends Vehicle {

public int speed() { return 60; } }

class RaceCar extends Car {

public int speed() { return 150; } }

public class TestCar {

public static void main(String[] args) { RaceCar racer = new RaceCar();

Car car = new RaceCar();

Vehicle vehicle = new RaceCar();

System.out.println(racer.speed() + \vehicle.speed()); } } A.0, 0, 0 B.150, 60, 0 C.150, 150, 150 D.抛出运行时异常 正确答案:C

当子类重写了父类的方法后,该重写方法被调用时(无论是通过子类的引用调用还是通过父类的引用调用),运行的都是子类重写后的版本

42.

(单选)题目: 下列代码的输出结果是: ()。 public class A {

public void info(){ System.out.println(\ public class B extends A{

public void info(){ System.out.println(\public static void main(String[] args) { B b=new B(); A a=b; a. info(); } }

A.B info A info

B.A info B info C.A info D.B info 正确答案:D

当子类重写了父类的方法后,该重写方法被调用时(无论是通过子类的引用调用还是通过父类的引用调用),运行的都是子类重写后的版本

43.

(单选)请看下列代码:

class ClassA {}

class ClassB extends ClassA {} class ClassC extends ClassA {} public class Test{

public static void main(String[] args) { ClassA p0 = new ClassA(); ClassB p1 = new ClassB(); ClassC p2 = new ClassC(); ClassA p3 = new ClassB(); ClassA p4 = new ClassC(); <插入代码> } }

可以在<插入代码>处,填入的代码正确的是() A.p0 = p1;A类和B类有继承关系 B.p1 = p2;B类和C类没有任何关系 C.p2 = p4;小类型向大类型转,要强转

D.p2 = (ClassC)p1; B类和C类没有任何关系,不能强制转换类型 正确答案:A

44.(单选)下列代码的运行结果是()。

public class Animal {

public String noise() { return \public static void main(String[] args) { Animal animal = new Dog();

Cat cat = (Cat)animal;这里animal引用指向狗对象,为Animal类型,大类型不能向小类型转换。和Cat没有实现关系, 也不能强制转换 System.out.println(cat.noise()); } } class Dog extends Animal {

public String noise() { return \class Cat extends Animal {

public String noise() { return \ A.peep B.bark C.meow

D.抛出运行时异常 正确答案:D

45.(单选)类A,B和C的定义如下: public class A { public void f() {

System.out.println(\ public class B extends A { public void f() {

System.out.println(\public class C {

public void g(A a) {

System.out.println(\f(); }

public void g(B b) {

System.out.println(\f(); } } 运行下面程序: C c = new C(); A a = new B(); c.g(a);

输出的结果是:()。 A.g(A a) A.f() B.g(A a) B.f() C.g(B b) A.f() D.g(B b) B.f() 正确答案:B 46.

(多选)请看下列代码: package com.tarena; public class Geodetics {

public static final double DIAMETER = 12756.32; } 访问静态常量DIAMETER的方式正确的是: A. import com.tarena.Geodetics; public class TerraCarta { public double halfway(){

return Geodetics.DIAMETER/2.0; } } B. import com.tarena.Geodetics; public class TerraCarta {

public double halfway(){ return DIAMETER/2.0; } } C. import com.tarena; 没导入类 public class TerraCarta { public double halfway(){

return Geodetics.DIAMETER/2.0; } } D. import com.tarena.*; public class TerraCarta { public double halfway(){

return Geodetics.DIAMETER/2.0; } } 正确答案:AD常量可以用类名点出来

47.(多选)在Java语言中,下列说法正确的是()。 A.一个接口可以继承多个接口 B.一个类可以继承多个类 C.一个类可以实现多个接口 D.一个类可以有多个子类 正确答案:ACD

48.(多选)请看下列代码: class One {

public One foo() { return this; } }

class Two extends One { public One foo() { return this; } } class Three extends Two { <插入代码> }

下列选项中的代码,放置在<插入代码>处无编译错误的是: A.public void foo() { }

B.public Object foo() { return this; } C.public Two foo() { return this; } D.public One foo() { return this; }

正确答案:CD 49.

(多选)查看如下代码: public class Foo { public void method(String str,int age){} }

下列选项中,和 Foo 类中 method 方法重载的方法是()。 A.public int method(String str,int age){} B.public void method(int year,String s){} C.public int method(int year,String s){} D.public int method(String str){} 正确答案:BCD

重载要求方法名相同,参数列表不同,与返回值无关

50.

(多选)查看如下代码: class A {

protected int method (int a, int b) { return 0; } } 下列选项中,可以在 A 的子类中使用的是()。

A.public int method (int a, int b) { return 0; } B.private int method(int a, int b) { return 0; } C.private int method(int a, long b) { return 0; } D.public short method(int a, int b) { return 0; }

正确答案:AC

本文来源:https://www.bwwdw.com/article/6rfa.html

Top