Thread cThread = new Thread(test.new B()); cThread.start(); }
class A extends Thread{ public void run() {
// TODO Auto-generated method stub for(int i=0;i<100;i++){ n++;
System.out.println(\+n); } } }
class B implements Runnable { @Override
public void run() {
// TODO Auto-generated method stub for(int i=0;i<100;i++){ n--;
System.out.println(\+n); } } }
}
//线程同步的话就是 public class Test{
private static int n=100;
public static void main(String[] args){ Test test = new Test(); A a = test.new A(); a.start();
Thread cThread = new Thread(test.new B()); cThread.start(); }
class A extends Thread{ public void run() {
// TODO Auto-generated method stub for(int i=0;i<100;i++){ synchronized(Test.class){ n++;
System.out.println(\+n); } } }
}
class B implements Runnable { @Override
public void run() {
// TODO Auto-generated method stub for(int i=0;i<100;i++){ synchronized(Test.class){ n--;
System.out.println(\+n); } } } } }
—————————————–Part II,总计30分————————————————–
一、选择题(共7题,每题2分,共14分) 1.下面哪个是java的关键字 B A NULL B new C instanceOf
D wend
2.下面语句哪个是正确的 A char s=’abc’; B long l=oxfff; C float f=0.45; D double d =0.8E-3;
3.public class ExampleStringBuffer {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer(“mytest”); System.out.println(“buffer=” + sb); System.out.println(“length=” + sb.length()); } }
程序的运行结果中在“length=”后输出的值是 B A 10 B 6 C 20 D 30
4.在下列的整数数据类型中,需要内存空间最小的是 D A short B long
C int D byte
5. public class MyFor {
static boolean out(char input){ System.out.print(input); return true; }
public static void main(String arg[]){ int i=0;
for(out(‘A’);out(‘B’)&&i<2;out(‘C’)){ i++; out(‘D’); } } }
程序的运行结果是 A A ABDCBDCB B ABCDABCD C 程序编译时出错 D 程序运行时异常
6.在Eclipse中程序代码自动排版的热键是:C