云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 1609第一次月考详细解析

1609第一次月考详细解析

  • 62 次阅读
  • 3 次下载
  • 2025/5/26 3:53:00

System.out.print(foo3.num+\System.out.println(foo3.x); } } A.3,3 B.1,3 C.3,4 D.1,4 正确答案:D

静态变量,也就是在变量前加了static 的变量;也叫类变量,只有一份,存在方法区 实例变量也叫对象变量,即没加static 的变量;

区别在于:静态变量和实例变量的区别在于:静态变量是所有对象共有,其中一个对象将它值改变,其他对象得到的就是改变后的结果;而实例变量则属对象私有,某一个对象将其值改变,不影响其他对象

38.

(单选)请看下列程序的输出结果是: public class Item { private String desc;

public String getDescription() { return desc; }

public void setDescription(String d) { desc = d; }

public static void modifyDesc(Item item, String desc) { item = new Item();

item.setDescription(desc); }

public static void main(String[] args) {

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

搜索更多关于: 1609第一次月考详细解析 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

System.out.print(foo3.num+\System.out.println(foo3.x); } } A.3,3 B.1,3 C.3,4 D.1,4 正确答案:D 静态变量,也就是在变量前加了static 的变量;也叫类变量,只有一份,存在方法区 实例变量也叫对象变量,即没加static 的变量; 区别在于:静态变量和实例变量的区别在于:静态变量是所有对象共有,其中一个对象将它值改变,其他对象得到的就是改变后的结果;而实例变量则属对象私有,某一个对象将其值改变,不影响其他对象 38. (单选)请看下列程序的输出结果是: public class Item { private String desc; public String getDescription() { return

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com