文章目录
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: