JavaSE笔试题

JavaSE笔试题
一.选择题(每小题1分,共30题,总计30分)

  1. 下面哪些是合法的标识符?( )
    A.$num B.class C.*name D.1NO

  2. 下面程序运行的结果是( )
    Public class Example{
    Public static void main(String[] args){
    Int i=100;
    Switch(i){
    case 100:
    System.out.print(i);
    case 200:
    System.out.print(i);
    case 300:
    System.out.print(i);
    }
    }
    }
    A.无任何输出 B.编译错误 C.输出 100100100 D.输出100

3.哪些不是java关键字?( )
A.super B.final C.public D.string

4.下面程序运行的结果是( )
Class Example{
Public static void main(String[] args){
Int x;
double y= -10.9;
x=(int)y;
System.out.print(x +” ”);
y = 10.9;
x = (int)y;
system.out.print(x);
}
}
A.-11 B.-11 11 C.-10 10 D.-10 11

5.下面程序运行的结果是( )
public class Example{
int x = 12;
public void method(int x){
x += x;
System.out.print(x);
}
Public static void main(String[] args){
Example t = new Example();
t.method(5);
}
}
A.5 B.10 C.12 D.24

  1. 下列数组声明语句中,错误的是:( )
    A.int[] arr = new int[]{};
    B.int[] arr = new int[];
    C.int[] arr = {};
    D.int[][] arr = new int[2][]

  2. 在Java语言中,下列说法正确的是:( )
    A. Java访问修饰符按照访问范围由低到高的排列顺序是public,default,protected,private
    B. private可以用于外部类的声明
    C. 一个Java源文件中声明为public的外部类只能有一个
    D. protected声明的方法不可以被子类重写

  3. 如下方法声明中,错误的是()
    A. public void say() { System.out.print(“Hi”); }
    B. public void say() { System.out.print(“Hi”);return; }
    C. public int say() { System.out.print(“Hi”);return; }
    D. public int say() { System.out.print(“Hi”);return 0; }

  4. public class Bootchy {
    int bootch;
    String snootch;

public Bootchy() {
this(“snootchy”);
System.out.print("first ");
}
public Bootchy(String snootch) {
this(420, “snootchy”);
System.out.print("second ");
}
public Bootchy(int bootch, String snootch) {
this.bootch = bootch;
this.snootch = snootch;
System.out.print("third ");
}
public static void main(String[] args) {
Bootchy b = new Bootchy();
System.out.print(b.snootch + " " + b.bootch);
}}
的执行结果是()
A.first second third snootchy 420
B.third second first snootchy 420
C.third first second snootchy 420
D.first second first third snootchy 420

  1. 有变量声明如下:
    short b = 120;
    下列语句中,错误的是()
    A.short s = b;
    B.int i = b;
    C.byte s1 = b;
    D.long l = b;

  2. 下列代码的输出结果是( ):
    int j=0;
    for(int i=0;i<100;i++){
    j=j++;
    }
    System.out.println(j);
    A.0 B.99 C.100 D.101

  3. 程序的执行结果是( a)
    public class Test {
    public static void main(String [] args){
    String str1= new String(“abc”);
    String str2 = new String(“abc”);
    String str3=str1;
    if(str1.equals(str2)){
    System.out.println(“true”);
    }else{
    System.out.println(“false”);
    }
    if(str1==str3){
    System.out.println(“true”);
    }else{
    System.out.println(“false”);
    }
    }
    A.true true
    B.true false
    C.false true
    D.false false

  4. 下列数组声明语句中,错误的是:( )
    A. int[] arr = new int[8];
    B. int[] arr = new int[8]{};
    C. int[] arr = {};
    D. int[] arr = new int[]{};

  5. 在Java语言中,字符串“Java程序员”在内存中所占用的字节数是:( )
    A.10 B.7 C.13 D.14

  6. 下列代码编译和运行的结果是:( )
    public static void main(String[] args) {
    String[] elements = { “for”, “tea”, “too” };
    String first = (elements.length > 0) ? elements[0] : null;
    System.out.println(first);
    }
    A.编译出错
    B.输出:tea
    C.输出:for
    D.输出:null

  7. 下列属于不合法Java标识符的是( )
    A. _mem
    B. 12a
    C. M12
    D. $12

  8. 下列代码的输出结果是:( )
    String str1 = “WhatisJava”;
    String str2 = “WhatisJava”;
    System.out.print(str1.equals( str2));
    System.out.print(",");
    String str3 = new String(“WhatisJava”);
    System.out.println(str1.equals(str3));
    A. true,false B. false,false C. false,true D. true,true

  9. 下列代码的运行结果是()
    public static void main(String[] args) {
    String str = “420”;
    str += 42;
    System.out.print(str);
    }
    A.42 B.420 C.462 D.42042

  10. 下列代码的输出结果是: ()
    public class A {
    public void info(){
    System.out.println(“A info”);
    }
    }
    public class B extends A{
    public void info(){
    System.out.println(“B info”);
    }
    public static void main(String[] args) {
    B b=new B();
    A a=b;
    a.info();
    }
    }
    A. B info A info
    B. A info B info
    C. A info
    D. B info

  11. 运行下面的程序:
    int a = 100;
    int b = 200;
    a = a + b;
    b = a - b;
    a = a - b;
    System.out.println(“a=” + a + “, b=” + b);
    输出的结果是:()
    A.a=100, b=300
    B.a=100, b=200
    C.a=200, b=100
    D.a=300, b=200

  12. 查看如下代码:
    class HasStatic{ //第1行
    private static int x=100;//第2行
    public static void main(String args[ ]){ //第3行
    HasStatic hs1=new HasStatic( ); //第4行
    hs1.x++; //第5行
    HasStatic hs2=new HasStatic( ); //第6行
    hs2.x++; //第7行
    hs1=new HasStatic( ); //第8行
    hs1.x++; //第9行
    HasStatic.x–; //第10行
    System.out.println(“x=”+x); //第11行
    } //第12行
    } //第13行
    对于此代码,下列描述中,正确的是( )
    A.5行不能通过编译,因为引用了私有静态变量
    B.10行不能通过编译,因为x是私有静态变量
    C.程序通过编译,输出结果为:x=103
    D.程序通过编译,输出结果为:x=102

  13. 运行下面的语句:
    String s="";
    if(s==s+0){
    System.out.println(“Hello World”);
    }
    编译,运行的结果是:()
    A.Hello World
    B.无输出
    C.编译错误
    抛出运行时异常

  14. 程序的执行结果是( )
    public class Test {
    int x;
    public static void main(String [] args){
    Test t = new Test();
    t.x=5;
    change(t);
    System.out.println(t.x);
    }
    public static void change(Test t){
    t.x=3;
    }
    }
    A.5 B.3 C.0 D.4

  15. 请看下列代码:( )
    public class Foo {
    public void method(String str,int age){}
    }
    和Foo类中method方法重载的方法是:
    A. public int method(String str,int age){}
    B. public void method(String s,int year){}
    C. protected void method(String s, int year){}
    D. public int method(int year,String s){}

  16. 在Java语言中,下列说法不正确的是()
    A. 一个接口可以继承多个接口
    B. 一个类可以继承多个类
    C. 一个类可以实现多个接口
    D. 一个类可以有多个子类

  17. 下列类的定义,错误的是()
    A. public class Test extends Object{……}
    B. final class Operators{……}
    C. class Point{……}
    D. void class Point{……}

  18. 下列赋值语句中,会有编译错误的是( )
    A. int a = 8888888888;
    B. char b = 1000+300;
    C. long c = 100;
    D. int d = ‘a’+‘b’+‘c’;

  19. 请看下列代码:
    package com.chinasofti;
    public class Geodetics {
    public static final double DIAMETER = 12756.32;
    }
    访问静态常量DIAMETER的方式正确的是( ):
    A.import com. chinasofti.Geodetics; public class TerraCarta { public double halfway(){ return Geodetics.DIAMETER/2.0; } }
    B.import com. chinasofti.Geodetics; public class TerraCarta { public double halfway(){ return DIAMETER/2.0; } }
    C.import com. chinasofti; public class TerraCarta { public double halfway(){ return Geodetics.DIAMETER/2.0; } }
    D.import com. chinasofti.*; public class TerraCarta { public double halfway(){ return DIAMETER/2.0; } }

  20. 查看如下代码:
    public class Foo {
    public void method(String str,int age){}
    }
    下列选项中,不属于Foo 类中 method 方法重载的方法是( )
    A.public int method(String str,int age){}
    B.public void method(int year,String s){}
    C.public int method(int year,String s){}
    D.public int method(String str){}

  21. 在<插入代码>处,填入下列代码编译正确的是:()
    public void foo(int[] x) {
    <插入代码>
    }
    A.foreach(int z : x) System.out.println(z);
    B.for(short 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]);

二、简答题(每题5分)
1.请写出java的基本数据类型。
2.请简述String、StringBuffer和StringBuilder的区别。
3.请简述finally和final两个关键字的区别。
4.请简述错误和异常的区别。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值