java2

  • Post author:
  • Post category:java


1.下面哪些是Thread类的方法()

A start() B run() C exit() D getPriority()

答案:ABD Thread类的getPriority()方法用于检查线程的优先级。 当创建一个线程时,它会为它分配一些优先级。线程的优先级可以由JVM或程序员在创建线程时明确指定。线程的优先级在1到10的范围内。线程的默认优先级为5。

指出下列程序运行的结果 ()

public class Example {


2.程序运行结果()

String str = new String(“good”);

char[] ch = { ‘a’, ‘b’, ‘c’ };

public static void main(String args[]) {


Example ex = new Example();

ex.change(ex.str, ex.ch);

System.out.print(ex.str + ” and “);

System.out.print(ex.ch);

} public void change(String str, char ch[]) {


str = “test ok”;

ch[0] = ‘g’;

}

}

A、 good and abc

B、 good and gbc

C、 test ok and abc

D、 test ok and gbc

答案:B Java中的“传值”和“传引用”问题,当基本类型作为参数传入方法时,无论该参数在方法内怎样被改变,外部的变量原型总是不变的,因为方法内部有外部变量的一份拷贝,对这个拷贝的更改不会改变外部变量的值。但当方法传入的参数为非基本类型时(也就是说是一个对象类型的变量), 方法里面改变参数变量的同时变量原型也会随之改变

3.下面的方法,当输入为2的时候返回值是多少?()

public static int getValue(int i) {


int result = 0; switch (i) { case 1:

result = result + i; case 2:

result = result + i * 2; case 3:

result = result + i * 3;

} return result;

}

A0

B2

C4

D10

答案:D

解析:注意这里case后面没有加break,所以从case 2开始一直往下运行。



版权声明:本文为weixin_41439692原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。