JAVA基础、面向对象
1.
下列代码的输出结果是:
public
class Yikes {
public static void go(Long n)
{
System.out.println("Long ");
}
public static void go(Short n)
{
System.out.println("Short ");
}
public static void go(int n) {
System.out.println("int ");
}
public static void main(String[] args)
{
short y = 6;
long z = 7;
go(y);
go(z);
}
}
A.
Long
Long
B.
Short
Long
C.
int
Long
D.
int
int
正确答案:C
2.
下面不属于Java语言特点的是:
A.
平台无关
B.
面向对象
C.
支持指针类型
D.
垃圾回收机制
正确答案:C
3.
下面关于final说法错误的是:()
A.
final修饰类时,该类不能被继承。
B.
final修饰方法时,该方法不能被重写。
C.
当引用到使用static
final 修饰的常量时,将采用编译期绑定的方式。
D.
当使用final和abstract共同修饰一个类时,final应至于abstract之前。
正确答案:D
4.
下列代码的输出结果是()。
public
static void main(String[] args) {
int[] one=new int[]{4,6,8};
int[] two=new int[]{1,3,5,7,9};
System.arraycopy(one, 1, two, 2, 2);
System.out.println(Arrays.toString(two));
}
A.
[1, 3, 7,
4, 6]
B.
[1, 3, 5,
7, 8]
C.
[1, 3, 5,
6, 9]
D.
[1, 3, 6,
8, 9]
正确答案:D
5.
下列代码的输出结果是()。
public
static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
System.out.print("Cat");
}
};
Thread t = new Thread(r) {
public void run() {
System.out.print("Dog");
}
};
t.start();
}
A.
Cat
B.
Dog
C.
没有任何输出
D.
抛出运行时异常
正确答案:B
6.
运行下面的程序:
Calendar c
= Calendar.getInstance();
c.set(Calendar.YEAR, 2012);
c.set(Calendar.MONTH, Calendar.SEPTEMBER);
c.set(Calendar.DATE, 31);
SimpleDateFormat sdf = new
SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(c.getTime()));
输出的结果是:()。
A.
2012-10-1
B.
2012-10-01
C.
2012-09-30
D.
2012-9-30
正确答案:B
7.
下列代码中对象锁的使用效率最高的是:
A. public
class Foo{
private Object o1,o2;
public synchronized void
methodA(){对o1进行操作}
public synchronized void
methodB(){对o1进行操作}
public synchronized void
methodC(){对o2进行操作}
public synchronized void
methodD(){对o2进行操作}
}
B. public
class Foo{
private Object lock = new
Object();
private Object o1,o2;
public void
methodA(){synchronized(lock){对o1进行操作}}
public void
methodB(){synchronized(lock){对o1进行操作}}
public void
methodC(){synchronized(lock){对o2进行操作}}
public void
methodD(){synchronized(lock){对o2进行操作}}
}
C. public
class Foo{
private Object lock = new Object(),lock2
= new Object();
private Object o1,o2;
public void
methodA(){synchronized(lock){对o1进行操作}}
public void
methodB(){synchronized(lock){对o1进行操作}}
public void
methodC(){synchronized(lock2){对o2进行操作}}
public void
methodD(){synchronized(lock2){对o2进行操作}}
}
D. public
class Foo{
private Object lock = new Object(),lock2
= new Object();
private Object o1,o2;
public void
methodA(){synchronized(lock){对o1进行操作}}
public void
methodB(){synchronized(lock2){对o1进行操作}}
public void
methodC(){synchronized(lock){对o2进行操作}}
public void
methodD(){synchronized(lock2){对o2进行操作}}
}
正确答案:C
8.
下列代码编译和运行的结果是()
public
class Foo {
public static void main(String[] args) {
list.add(new B());
list.add(new C());
for (A a : list) {
a.x();
a.y();
}
}
}
interface
A {
void
x();
}
class B
implements A {
public void x() {}
public void y() {}
}
class C
extends B {
public void x() {}
}
A.
代码运行没有输出
B.
运行时抛出异常
C.
代码a.y();行,编译错误
D.
正确答案:C
9.
请看下列代码的输出结果是:
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