01-综合测试(带答案)

这是一份关于Java编程的基础测试,包含选择题、简答题、设计题和实践题,全面覆盖了Java语法、异常处理、数组、反射、对象拷贝、线程池、JVM结构、数据库查询等方面的知识。通过这份测试,可以检验和提升Java程序员的基础技能。
摘要由CSDN通过智能技术生成

选择题(2/25)

  1. 如下代码中哪行语句是正确的(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.

  1. 下面程序代码块运行结果为(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	
  1. 以下程序的输出结果是什么(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
  1. 如下语句的输出结果是什么?(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
  1. 如下对于数组的定义说法正确的是?(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正确
  1. 阅读如下代码,对运行结果说法正确的是:(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
  1. 选项中哪个放到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]); 


  1. 阅读如下代码选择正确的运行结果? ©
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 

  1. 以下程序的运行结果是(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. 编译失败
  1. 以下程序的运行结果是: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
  1. 请指出以下代码的运行结果?(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
  1. 以下程序在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
  1. 下面的程序输出的结果是?(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. 编译失败

  1. 下面程序的运行结果:(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. 编译错误
  1. 下列哪种异常是检查异常,需要在编写程序时声明 (C)
A. NullPointerException
B. ClassCastException 
C. FileNotFoundException 
D. IndexOutOfBoundsException

  1. 如下代码运行时,正确的输出结果应该是什么?(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. 编译错误
  1. 如下代码的运行结果是?(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. 编译错误
  1. 阅读如下代码,给出正确运行结果?(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
  1. 阅读如下代码,给出正确的输出结果。(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");
      
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值