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

叨叨两句

  1. 剁手啊~剁手啊~java

牛客网——java专项练习017

1

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

  1. 线程

  2. rest

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

2

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

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. 12it

正确答案: 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 (正确)io

  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()方法使其从新启动