1609第一次月考详细解析 联系客服

发布时间 : 星期日 文章1609第一次月考详细解析更新完毕开始阅读d174d613eef9aef8941ea76e58fafab069dc4409

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