选择题(2/25)
- 如下代码中哪行语句是正确的(B)
1. String #name = "Jane Doe";
2. int $age=24;
3. Double _height = 123.5;
4. double ~temp = 37.5;
A. 1,2.
B. 2,3.
C. 3,4.
D. 1,4.
- 下面程序代码块运行结果为(D)
Integer b = 200;
Integer a = 200;
int c = 200;
System.out.println(a.equals(b));
System.out.println(a == c);
A.fasle;true
B.false;false
C.true;fasle
D.true;true
- 以下程序的输出结果是什么(B)
public class Test03 {
private int x = 100;
public static void main(String[] args) {
int x =5;
boolean b1 = true;
boolean b2 = false;
if((x==4) && !b2)
System.out.print("l");
System.out.print("2");
if ((b2 = true) && b1)
System.out.print("3");
}//23
}
A.123
B.23
C.3
D.2
- 如下语句的输出结果是什么?(A)
public class Test04 {
public static void main(String[] args) {
int x=0;
int y=10;
do {
y--;
if(y==6)continue;
++x;
} while (x < 5);
System.out.print(x + "," + y);
}
}
A.5,4
B.4,5
C.5,6
D.6,6
- 如下对于数组的定义说法正确的是?(A)
1.int[] a={1,2,3};
2.int[] b=new int[5];
3.int[][] c={
{1},{2}};
4.int[][]d =new int[5][];
A.1,2,3,4都正确
B.只有1,2正确
C.只有1正确
D.只有1,3正确
- 阅读如下代码,对运行结果说法正确的是:(B)
public class Test06 {
static void f1(int...x) {
System.out.println("x.length="+x.length);
}
static void f1(int y){
System.out.println("y="+y);
}
public static void main(String[] args) {
f1(10);
}
}
A.编译错误
B.输出y=10
C.输出x.length=1
D.输出y=10;x.length=1
7.阅读如下代码,其运行结果正确的是?(D)
public class Test07 {
public static void main(String[] args) {
int a=10;
int b[]={20};
change(a,b);
System.out.println(a+","+b[0]);
}
static void change(int a,int[] b){
a=11;
b[0]=21;
}
}
A.10,20
B.11,21
C.11,20
D.10,21
- 选项中哪个放到code处可以保证程序正常编译? (BD)
public class Test08 {
static void foo(int...x){
//code(插入代码处)
}
}
A. foreach(x) System.out.println(z);
B. for(int z : x) System.out.println(z);
C. while( x.hasNext()) System.out.println( x.next());
D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);
- 阅读如下代码选择正确的运行结果? ©
public class Test09 {
public static void main(String[] args) {
String o = "";
z :
for(int x=0; x<3; x++){
for(int y=0; y<2; y++){
if(x == 1) break;
if(x==2 && y==1) break z;
o = o + x + y;
}
}
System.out.println(o);
}
}
A. 编译失败
B. 0001
C. 000120
D. 00012021
- 以下程序的运行结果是(D)
public class Test10 {
static void f1(){
throw new RuntimeException();
}
static void f2(){
f1();
throw new Exception();
}
public static void main(String[] args) {
f2();
}
}
A. 程序会抛出RuntimeException
B. 程序会抛出Exception
C. 程序会抛出RuntimeException,Exception
D. 编译失败
- 以下程序的运行结果是:D
public class Test11 {
static void test() throws RuntimeException{
try{
System.out.print("test");
throw new RuntimeException();
}catch(Exception e){
System.out.print("exception");
}
}
public static void main(String[] args){
try{test();}
catch(RuntimeException ex){
System.out.print("runtime");
}
System.out.print("end");
}
}
A. test end
B. 编译失败
C. test runtime end
D. test exception end
- 请指出以下代码的运行结果?(D)
public class Test12 {
private static Integer b;
public static void main(String[] args){
int a = 10;
print(a);
print(b);
b = a;
print(b);
}
private static void print(Integer value){
int add = value+5;
System.out.println(add);
}
}
A. 15,5,20
B. 编译失败
C. 15,5,15
D. 运行时出现NullPointerException
- 以下程序在JDK1.8的环境下,描述正确的是(C)
class A{
int a=10;
public A(int a){
this.a=a;
}
}
class B extends A{
int a;
public B(int a){
this.a=a;
}
}
public class Test13 {
public static void main(String[] args) {
A a=new B(20);
System.out.println(a.a);
}
}
A. 10
B. 20
C. 编译失败
D. 0
- 下面的程序输出的结果是?(D)
interface IC{
int M = 10;
}
class C implements IC{
int M = 20;
int N = 30;
}
public class Test14{
public static void main(String[] args) {
IC c1=new C();
System.out.println(c1 instanceof C);
System.out.println(c1.M);
System.out.println(c1.N);
}
}
A. true,10,30
B. false,10,30
C. true,20,30
D. 编译失败
- 下面程序的运行结果:(B)
public class Test15 {
public static void main(String args[]) {
Thread t = new Thread() {
public void run() {
pong();
}
};
t.run();
System.out.print("ping");
}
static void pong() {
System.out.print("pong");
}
}
A. pingpong
B. pongping
C. pingpong和pongping都有可能
D. 编译错误
- 下列哪种异常是检查异常,需要在编写程序时声明 (C)
A. NullPointerException
B. ClassCastException
C. FileNotFoundException
D. IndexOutOfBoundsException
- 如下代码运行时,正确的输出结果应该是什么?(D)
package com.cy.test;
import java.util.ArrayList;
import java.util.List;
public class Test16 {
static void print(List<Object> list){
System.out.println(list);
}
public static void main(String[] args) {
List<Integer> list2=new ArrayList<>();
list2.add(100);
list2.add(100);
print(list2);
}
}
A. [100]
B. [100,100]
C. 输出list对象地址
D. 编译错误
- 如下代码的运行结果是?(D)
package com.cy.test;
enum Gender{
MALE,FEMALE,NONE;
public Gender(){}
public static void value(Gender gender){
switch (gender){
case MALE: System.out.println("男士");break;
case FEMALE: System.out.println("女士");break;
default: System.out.println("未知");
}
}
}
public class Test17 {
public static void main(String[] args) {
Gender.value(Gender.MALE);
}
}
A. 男士
B. 女士
C. 未知
D. 编译错误
- 阅读如下代码,给出正确运行结果?(D)
package com.cy.test;
@Target(ElementType.TYPE)
@interface Entity{
String value();
}
@Entity(value="obj")
class Obj{}
public class Test18 {
public static void main(String[] args) {
Entity entity=Obj.class.getAnnotation(Entity.class);
System.out.println(entity.value());
}
}
A. obj
B. 编译错误
C. 运行时会出现空指针异常
D. null
- 阅读如下代码,给出正确的输出结果。(B)
package com.cy.test;
import java.util.LinkedHashMap;
public class Test19{
public static void main(String[] args) {
LinkedHashMap<String,Object> map=
new LinkedHashMap<>(3,0.75f,true);
map.put("A", 100);
map.put("B", 200);
map.get("A");