java基础测试题3
1. :,
1. public class Test {
2. public static void main(String [] abc) {
3. unsigned int x = 10;
4. for (int y=0; y<5; y++, x--)
5. (" " + x);
6. }
7. }
指出哪一行有错误? (Choose one.)
A. 第2行
B. 第3行
C. 第4行
答案:B
解析:unsigned 这个是在C语言中才有的
2. :
1. interface Count {
2. short counter = 0;
3. void countUp();
4. }
5. public class TestCount implements Count {
6.
7. public static void main(String [] abc) {
8. TestCount t = new TestCount();
9. ();
10. }
11. public void countUp() {
12. for (int x = 6; x>counter; x--, ++counter) {
13. (" " + counter);
14. }
15. }
16. }
此程序的错误在于? (Choose one.)
A. 第2行
B. 第7行
C. 第8行
D. 第12行
答案:D
解析:考查接口和final 参看下面的代码
package a;
public class test2 {
interface Count {//接口只可以定义static final成员变量
public static final short counter = 0;//public static final
//这个是默认有的.
void countUp();
}
}
package a;
import ;
public class test3 implements Count {
public static void main(String[] abc) {
test3 t = new test3();
();
}
public void countUp() {
for (int x = 6; x > counter; x--, ++counter) {
//这里的counter
//
//回顾final,finally,
//finalize 的用法
/*
* final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。
*/
(" " + counter);
}
}
}
3. :
java基础测试题3 来自淘豆网m.daumloan.com转载请标明出处.