十道经典的php技术问题,这十道10道Java题你会做吗?考考你的水平

/**

*这10道题都是我做过的,做错或者觉得需要复习的有价值的,整理出来也考考大家

*有更好的建议欢迎提出来

*/

1.代码输出结果是public class Test {

public static void main(String [] args){

System.out.println(new B().getValue());

}

static class A{

protected int value;

public A(int v) {

setValue(v);

}

public void setValue(int value){

this.value = value;

}

public int getValue(){

try{

value++;

return value;

} catch(Exception e){

System.out.println(e.toString());

} finally {

this.setValue(value);

System.out.println(value);

}

return value;

}

}

static class B extends A{

public B() {

super(5);

setValue(getValue() - 3);

}

public void setValue(int value){

super.setValue(2 * value);

}

}

}

A.11 17 34

B.22 74 74

C.6 7 7

D.22 34 17

2.下面的程序 编译运行后,在屏幕上显示的结果是()public class test {

public static void main(String args[]) {int x,y;x=5>>2;y=x>>>2;System.out.println(y);}

}

A.0

B.2

C.5

D.80

3.有如下代码:请写出程序的输出结果。public class Test

{

public static void main(String[] args)

{

int x = 0;

int y = 0;

int k = 0;

for (int z = 0; z < 5; z++) {

if ((++x > 2) && (++y > 2) && (k++ > 2))

{

x++;

++y;

k++;

}

}

System.out.println(x + ”” +y + ”” +k);

}

}

A.432

B.531

C.421

D.523

4.以下代码结果是什么?public class foo {

public static void main(String sgf[]) {

StringBuffer a=new StringBuffer(“A”);

StringBuffer b=new StringBuffer(“B”);

operate(a,b);

System.out.println(a+”.”+b);

}

static void operate(StringBuffer x,StringBuffer y) {

x.append(y);

y=x;

}

}

A.代码可以编译运行,输出“AB.AB”。

B.代码可以编译运行,输出“A.A”。

C.代码可以编译运行,输出“AB.B”。

D.代码可以编译运行,输出“A.B”。

5.给出以下代码,请给出结果. 0608class Two{

Byte x;

}

class PassO{

public static void main(String[] args){

PassO p=new PassO();

p.start();

}

void start(){

Two t=new Two();

System.out.print(t.x+””);

Two t2=fix(t);

System.out.print(t.x+” ” +t2.x);

}

Two fix(Two tt){

tt.x=42;

return tt;

}

}

A.null null 42

B.null 42 42

C.0 0 42

D.0 42 42

6. 下列代码片段中,存在编译错误的语句是()byte b1=1,b2=2,b3,b6,b8;

final byte b4=4,b5=6,b7;

b3=(b1+b2); /*语句1*/

b6=b4+b5; /*语句2*/

b8=(b1+b4); /*语句3*/

b7=(b2+b5); /*语句4*/

System.out.println(b3+b6);

A.语句2

B.语句1

C.语句3

D.语句4

7.What will be printed when you execute the following code? 0611class C {

C() {

System.out.print("C");

}

}

class A {

C c = new C();

A() {

this("A");

System.out.print("A");

}

A(String s) {

System.out.print(s);

}

}

class Test extends A {

Test() {

super("B");

System.out.print("B");

}

public static void main(String[] args) {

new Test();

}

}

A.BB

B.CBB

C.BAB

D.None of the above

8.以下代码执行后输出结果为( )0611public class ClassTest{

String str = new String("hello");

char[] ch = {'a','b','c'};

public void fun(String str, char ch[]){

str="world";

ch[0]='d';

}

public static void main(String[] args) {

ClassTest test1 = new ClassTest();

test1.fun(test1.str,test1.ch);

System.out.print(test1.str + " and ");

System.out.print(test1.ch);

}

}

A.hello and dbc

B.world and abc

C.hello and abc

D.world and dbc

9.以下代码将打印出public static void main (String[] args) {

String classFile = "com.jd.". replaceAll(".", "/") + "MyClass.class";

System.out.println(classFile);

}

A.com. jd

B.com/jd/MyClass.class

C.///MyClass.class

D.com.jd.MyClass

10.对于如下代码段class A{

public A foo(){return this;}

}

class B extends A{

public A foo(){

return this;

}

}

class C extends B

{

_______

}

可以放入到横线位置,使程序正确编译运行,而且不产生错误的选项是( )

A.public void foo(){}

B.public int foo(){return 1;}

C.public A foo(B b){return b;}

D.public A foo(){return A;}

相关文章:

相关视频:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值