Java编程语言习题

abstract

what will be the result of attempting to compile and run the following code?

abstract class MineBase {
   
    static int i;
    abstract void amethod();
}
public class Mine extends MineBase {
   
    public static void main(String arg[]){
   
        int [] ar=new int[5];
        for(i=0;i<ar.length;i++)
            System.out.println(ar[i]);
    }
}

A asequence of 5 0’s will be printed
B Error: ar is used before it is initialized
C Error Mine must be declared abstract
D IndexOutOfBoundes Error
C
在这里插入图片描述
A
在这里插入图片描述
B
在这里插入图片描述
D
在这里插入图片描述

static

写出编译运行后的结果

public class Student{
   
    static int num;
    int number;
    public static int add1()
    {
   
        num=num+1;
        return num;
    }
    public int add2()
    {
   
        number=number+1;
        return number;
    }
    public static void main(String argv[])
    {
   
        Student zhang=new Student();
        Student wang=new Student();
        Student jiang=new Student();
        System.out.println("zhang num="+add1());
        System.out.println("zhang number="+zhang.add2());
        System.out.println("wang num="+add1());
        System.out.println("wang number="+wang.add2());
        System.out.println("jiang num="+add1());
        System.out.println("jiang number="+jiang.add2());
    }
}

zhang num=1
zhang number=1
wang num=2
wang number=1
jiang num=3
jiang number=1


What will happen if you try to compile and run the following code

public class Test {
   
    public static void main(String[] arguments) {
   
        aMethod(arguments);
    }
    public void aMethod(String[] arguments) {
   
        System.out.println(arguments[1]);
    }
}

a)error Can’t make static reference to void amethod.
b)error method main not correct
c)error array must include parameter
d)aMethod must be declared with String

B
在这里插入图片描述
C
在这里插入图片描述
D
在这里插入图片描述在这里插入图片描述

Thread

public class Test extends Thread {
   
    static int aInt = 10;
    public static void main(String[] argv) {
   
        Test t = new Test();
        t.start();
    }
    public void run() {
   
        for (int i = 0 ; i < 4; i++) {
   
            System.out.println(++aInt);
        }
    }
}

11
12
13
14


下列说法不正确的是:
a)Java中线程是抢占式的;
b)Java中线程可以是抢占式也可以是分时的;
c)Java中线程可以共享数器;
d)Java中线程可以共享代码。


Which method should you define as the starting point of a new thread in a class from which new threads of execution can be made?
a)public static void main(String[] args)
b)public void run()
c)public void start()
d)public void init()
e)public void runnable()

There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread.
在这里插入图片描述
The following code would then create a thread and start it running:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值