1、下列说法错误的是?
A、Object类是所有Java类的顶层类,即类继承树的根。
B、如果一个类没有使用extends关键字扩展任何类,则编译器自动将创建的类视为Object类的子类。
C、Object类中提供了equals()方法来判定本对象和其他对象中的内容是否一致。
D、Object中提供的clone默认为浅克隆
参考答案:C 比较对象的虚地址
2、定义在Object类上的hashCode()方法的返回值类型是什么?
A、char
B、int
C、long
D、String
参考答案:B
equals boolean
hashcode int
toString String
3、下列代码输出结果是什么?
class Person {
static void sayHello() {
System.out.println("HelloWorld!");
}
}
public class Example {
public static void main(String[] args) {
((Person) null).sayHello();
}
}
A、编译失败
B、编译成功,运行时产生NullPointerException
C、输出HelloWorld!
D、输出空白字符串
参考答案:C
4、下列代码输出结果是什么?
class Person {
void sayHello() {
System.out.println("HelloWorld!");
}
}
public class Example {
public static void main(String[] args) {
((Person) null).sayHello();
}
}
A、编译失败
B、编译成功,运行时产生NullPointerException
C、输出HelloWorld!
D、输出空白字符串
参考答案:B
5、请问以下哪个方法不是定义在Object类中的?
A、toString()
B、equals(Object o)
C、println()
D、wait()
参考答案:C
finalize方法
equals方法 hashcode方法 toString方法 clone方法 getclass方法
6、toString方法的返回值是什么类型?
A、byte[]
B、Object
C、char[]
D、String
参考答案:D
7、一个类如果能被克隆,这个类必须实现哪个接口?
A、Cloneable
B、Serializable
C、Comparable
D、Copy
参考答案:A
8、Object类中的equals方法的功能,与哪个操作符相同?
A、=
B、==
C、&&
D、 ||
参考答案:B
9、请选择以下代码运行结果?
Integer i1=126;
Integer i2=126;
System.out.println("i1==i2"+(i1==i2));
A、true
B、false
C、编译错误
D、运行错误
参考答案:A
10、请选择以下代码运行结果?
Integer io1=new Integer(10);
Integer io2=new Integer(10);
System.out.println("io1==io2"+(io1==io2));
A、true
B、false
C、编译错误
D、运行错误
参考答案:B 比较的是地址
11、请选择以下代码运行结果?
Integer i3=1000;
Integer i4=1000;
System.out.println("i3==i4"+(i3==i4));
A、true
B、false
C、编译错误
D、运行错误
参考答案:B 范围是-128~127,1000超出范围
12、请选择以下代码运行结果?
Integer io3=new Integer(1000);
Integer io4=new Integer(1000);
System.out.println("io3==io4"+(io3==io4));
A、true
B、false
C、编译错误
D、运行错误
参考答案:B 比较的是地址
13、请选择以下代码运行结果?
Character c1=-13;
Character c2=-13;
System.out.println("c1==c2"+(c1==c2));
A、编译出错
B、运行出错
C、null
D、””
参考答案:A
java: 不兼容的类型: int无法转换为java.lang.Character
14、请选择以下代码运行结果?
Character c3=13;
Character c4=13;
System.out.println("c1==c2"+(c1==c2));
A、true
B、false
C、编译错误
D、运行错误
参考答案:A
15、请选择以下代码运行结果?
Boolean bo1=true;
Boolean bo2=true;
System.out.println("bo1==bo2"+(bo1==bo2));
A、true
B、false
C、编译错误
D、运行错误
参考答案:A
16、请选择以下代码运行结果?
Byte b1=10;
Byte b2=10;
System.out.println("b1==b2"+(b1==b2));
A、true
B、false
C、编译错误
D、运行错误
参考答案:A