java试题山东大学_Java系列试题(一)【JAVA基础、面向对象】

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值