每日10道JAVA题(20180727)

/**
 * 10道题系列会持续更新,每日的10道题都是我做过的,做错或者觉得需要复习的有价值的
 * 请关注我,每日和我一同进步,有更好的建议或有问题的请在评论区提出或私信我
 */

开始复习:温故而知新

安排!

1.What results from the following code fragment?

int i = 5;
int j = 10;
System.out.println(i + ~j);
A.Compilation error because”~”doesn’t operate on integers
B.-5
C.-6
D.15

2.以下集合对象中哪几个是线程安全的?( )
A.ArrayList
B.Vector
C.Hashtable
D.Stack

3.以下描述错误的一项是( )
A.程序计数器是一个比较小的内存区域,用于指示当前线程所执行的字节码执行  到了第几行,是线程隔离的
B.原则上讲,所有的对象都是在堆区上分配内存,是线程之间共享的
C.方法区用于存储JVM加载的类信息、常量、静态变量,即使编译器编译后的代码等数据,是线程隔离的
D.Java方法执行内存模型,用于存储局部变量,操作数栈,动态链接,方法出口等信息,是线程隔离的

4.代码输出结果是
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

5.关于类的叙述正确的是

A.在类中定义的变量称为类的成员变量,在别的类中可以直接使用
B.局部变量的作用范围仅仅在定义它的方法内,或者是在定义它的控制流块中
C.使用别的类的方法仅仅需要引用方法的名字即可
D.只要没有定义不带参数的构造函数,JVM都会为类生成一个默认构造函数

6.在java中,下列标识符不合法的有( )
A.new
B.$Usdollars
C.1234
D.car.taxi

7.以下定义一维数组的语句中,正确的是:()
A.int a [10]
B.int a []=new [10]
C.int  a[]
  int  a[]=new int [10]
D.int a []={1,2,3,4,5}

8.What will be printed when you execute the following code?
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

9.以下代码执行后输出结果为( )

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

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;}

猜你喜欢

转载自blog.csdn.net/stridebin/article/details/81255376
今日推荐