-
Java
测试
QUESTION NO: 1
Given:
1. public
class Test {
2. public
static void main(String args[]) {
3. class Foo {
4. publicinti = 3;
5. }
6. Object o = (Object)new Foo();
7. Foo foo = (Foo)o;
8. n(
9. }
10. }
结果是(不)
A. i = 3
B.
程序编译错误
.
C.
第
6
行
代码有问题
.
D.
第
7
行代码有问题
.
QUESTION NO: 2
Given:
下面代码有编译错误是(
A
)
A. float[] =
new float(3);
B. float f2[]
= new float[];
C. float[]
f1 = new float[3];
D. float
f3[] = new float[3];
E.
float f5[] = { 1.0f, 2.0f, 2.0f };
F. float f4[] = new float[] {
1.0f,2.0f,3.0f};
QUESTION
NO: 3
Given:
1. inti =1,j =10;
2. do {
3. if(i++> --j) {
4. continue;
5. }
6. } while (i<5);
7. n(
结果是(
D
)
A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 5
D. i = 5 and j = 6
E. i = 6 and j = 6
QUESTION
NO: 4
Given:
1.
interface Animal {
2.
voidsoundOff();
3. }
4.
5. class
Elephant implements Animal {
6. public void soundOff() {
7. n(
8. }
9. }
10.
11. class Lion implements Animal {
12. public void soundOff()
{
13. n(
14. }
15. }
16.
17. class Alpha1 {
18. static Animal get(
String choice ) {
19. if ( IgnoreCase(
20. return new Lion();
21. } else {
22. return new Elephant();
23. }
24. }
25. }
下面选项中代码哪个可以编译通过(
A
)
A. new
Animal().soundOff();
B.
Elephant e = new Alpha1();
C. Lion 1 = (
D.
new Alpha1().get(
QUESTION
NO: 5
Given:
1.
inti = 1,j = 10;
2. do {
3. if(i>j) {
4.
break;
5. }
6. j--;
7. } while (++i<5);
8. n(
程序结果是(
D
)
A. i = 6
and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6
E. i = 6 and j = 6
QUESTION NO: 6
Given:
你要想一个类能够访
问同一个包下其他类的属性,请问选择下面哪个选项(
C
)
p>
A. public
B. private
C.
protected
D. transient
E. default access
QUESTION NO: 7
Given:
1. int x
= 3;
2. int y = 1;
3. if (x = y) {
4. n(
5. }
代码结果是(
C
)
A. x = 1
B. x =
3
C.
程序编译错误
.
D.
代码运行结束后没有输出结果
.
E.
代码运行时候会有错误
.
QUESTION NO: 8
Given:
1. public
interface Foo {
2. int k =
4;
3. }
下面哪些选项能够
放到程序的第
2
行位置(
A,B,C<
/p>
)
A. final int k =
4;
B. public int k = 4;
C. static int k = 4;
D. abstract int k = 4;
E. volatile int k = 4;
F. protected int k = 4;
QUESTION NO: 9
Given:
1.
package test1;
2. public
class Test1 {
3. staticint
x = 42;
4. }
1.
package test2;
2. public
class Test2 extends 1 {
3.
public static void main(String[] args) {
4. n(
5. }
6. }
程序代码结果是
(
B
)
A.
x = 0
B. x = 42
C. Test2
类中第
2
行代码有错误
.
D.
Test1
类中第
3
行代码有错误
p>
.
E. Test2
< br>类中第
4
行代码有错误
.
QUESTION NO: 10
Given:
1. class
A {
2. protectedint
method1(int a, int b) { return 0; }
3. }
如果有一个类
B
继承了类
A
,则下面选项中的代码有哪些可以在类
B
中使用
(
AC
)
A. public intmethod1(int a, int b) {
return 0; }
B. private
intmethod1(int a, int b) { return 0; }
C. private intmethod1(int a, long b) {
return 0; }
D. public short
method1(int a, int b) { return 0: }
E. static protected intmethod1(int a,
int b) { return 0; }
QUESTION NO: 11
Given:
1. public class Delta {
2. staticboolean foo(char
c) {
3. (c);
4. return true;
5. }
6. public static void
main( String[] argv ) {
7.
inti =0;
8. for ( foo('A');
foo('B')&&(i<2); foo('C')){
9. i++
10. foo('D');