java面试题

1. 已知如下代码:

public class Test {
    long a[] = new long[10];
    public static void main(String[] args) {
        System.out.println(a[6]);
    }
}

请问哪个语句是正确的(A
A. When running,some error will occur.
B. When compile,some error will occur.
C. Output is null.
D. Output is 0.

2. 哪种定义数组是正确的?(C
A. Object[] objarr = new String[];
B. String[] objarr2 = new String[2]{“str1”,“str2”};
C. Object[] objarr3 = new String[]{“str1”,“str2”};
D. String[] objarr4 = new Object[]{“str1”,“str2”};

3. 这段代码的输出是什么?(D

public class Test {
    public static void main(String[] args) {
        int num = 1;
        System.out.println("changeNum()方法调用之前:num = " + num);
        changeNum(num);
        System.out.println("changeNum()方法调用之后:num = " + num);
    }
    public static void changeNum(int x){
        x = 2;
    }
}

       A. 1,2
       B. 1,3
       C. 2,2
       D. 1,1

4. Which of the following statements are true?(C,D
A. The == operator determines if the contents and type of two separate objects match.
B. The equals() method determines if reference values refer to the same object.
C. The equals() method returns true only when the contents of two objects match.
D. The class File overrides equals() to return true if the contents and type of two separate objects match.

5. 哪些返回true

String s = "hello",
String t = "hello",
char c[] = {'h','e','l','l','o'};

Which retrun true?(A,B,C
A. s.equals(t);
B. t.equals(new String(“hello”);
C. s == t;
D. t.equals( c );
E. t == c.

6.var a;
var b = ‘’;
var c = ‘test’;
var d = a||b||c;
此时d的值是多少?(D

A. true
B. undefined
C. false
D. ‘test’
E. ‘’
F. null

7. let x = 'fahk.jfdsfj.hf,hd,fhdshsd’字符串中的逗号替换为|符号,哪种操作正确(B
A. x.replace(’,’,’|’)
B. x.replcae(/,/g,’|’)
C. x.replace(’,’,’!’)
D. x.replace(’|’,’,’)

8. let x = [],x.push(‘1’),x.push(‘2’),x.push(‘3’),说法正确的是(A
A. 执行x.toString()一定不会报错
B. x.replice(x[0],‘0’),x中的数值会变
C. x.splice(3,1)后,x中的数量会变少
D. 数值类型不同,编译会报错

9. 以下说法正确的是(A,C,D
A. js中,数组可以通过一次for循环删除数组自身的多个元素
B. java中父类的对象一定访问不了子类的方法或者变量
C. Spring中我们也可以通过@Bean注解开启对象的单例
D. java中使用for循环遍历list集合的同时删除元素,集合元素会减少

10. 以下代码写法运行正确的是(A,B,C,D
A. let x=’’;
B. const x=undefined;
C. String a = null;
D. var x=’’;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值