77范文网 - 专业文章范例文档资料分享平台

1609第一次月考详细解析(6)

来源:网络收集 时间:2018-11-22 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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.(单选)下列代码的运行结果是()。

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库1609第一次月考详细解析(6)在线全文阅读。

1609第一次月考详细解析(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/296151.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: