/**
 *这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
立即学习“Java免费学习笔记(深入)”;
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.给出以下代码,请给出结果. 0608
class 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? 0611
class 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.以下代码执行后输出结果为( )0611
public 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道Java题你会做吗?考考你的水平的详细内容,更多请关注php中文网其它相关文章!
                        
                        java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号