【278天】我爱刷题系列(37)

叨叨两句

  1. 剁手啊~剁手啊~

牛客网——java专项练习017

1

可以把任何一种数据类型的变量赋给Object类型的变量。
正确答案: A 你的答案: B (错误)

基本数据类型赋值给object是因为自动装箱了

2

下面代码的输出结果是什么?

public class ZeroTest {
    public static void main(String[] args) {
     try{
       int i = 100 / 0;
       System.out.print(i);
  }catch(Exception e){
       System.out.print(1);
       throw new RuntimeException();
  }finally{
       System.out.print(2);
  }
      System.out.print(3);
 }
 }
  1. 3

  2. 123

  3. 1

  4. 12

正确答案: D   你的答案: 空 (错误)

还是需要理解Try...catch...finally与直接throw的区别:try catch是直接处理,处理完成之后程序继续往下执行,throw则是将异常抛给它的上一级处理,程序便不往下执行了。本题的catch语句块里面,打印完1之后,又抛出了一个RuntimeException,程序并没有处理它,而是直接抛出,因此执行完finally语句块之后,程序终止了

3

假设有以下代码String s = "hello";String t = “hello”;char c [ ] = {'h','e','l','l','o'};下列选项中返回false的语句是?
正确答案: B 你的答案: B (正确)

  1. s.equals (t);

  2. t.equals (c);

  3. s==t;

  4. t.equals (new String ("hello"));

首先==与equals是有明显区别的。
==强调栈中的比较,可以理解为地址比较
equals强调对象的内容比较
String s=“hello”;会在栈中生成hello字符串,并存入字符串常量池中。
String t=“hello” ;创建时,会在字符串常量池中寻找,当找到需要的hello时,不进行字符串的创建,引用已有的。 所以,s==t返回true,s.equals(t)也是true。
char c[]={'h','e','l','l','o'}; c==s这个是不存在的,==两边类型不同
t.equals(c)这个语句在anObject instanceof String这步判断不会通过,也就是cha[] 压根不能与String相比较,类型不是相同的。返回false

4

true、false、null、sizeof、goto、synchronized 哪些是Java关键字?

正确答案: E F 你的答案: A B C E F (错误)

  1. true

  2. false

  3. null

  4. sizeof

  5. goto

  6. synchronized

goto和const是保留字也是关键字。
1,Java 关键字列表 (依字母排序 共50组):
abstract, assert, boolean, break, byte, case, catch, char, class, const(保留关键字), continue, default, do, double, else, enum, extends, final, finally, float, for, goto(保留关键字), if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while
2,保留字列表 (依字母排序 共14组),Java保留字是指现有Java版本尚未使用,但以后版本可能会作为关键字使用:
byValue, cast, false, future, generic, inner, operator, outer, rest, true, var, goto (保留关键字) , const (保留关键字) , null

5

下列方法中哪个是线程执行的方法? ()
正确答案: A 你的答案: B (错误)

  1. run()

  2. start()

  3. sleep()

  4. suspend()

答案是A
run()方法用来执行线程体中具体的内容
start()方法用来启动线程对象,使其进入就绪状态
sleep()方法用来使线程进入睡眠状态
suspend()方法用来使线程挂起,要通过resume()方法使其重新启动
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值