JAVA试题求答案(一)
(1)对以下代码,哪些描述是正确的?()Integeri=newInteger(42);Long1=newLong(42);Doubled=newDouble(42.0)...
(1)对以下代码,哪些描述是正确的?( )
Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);
A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))
(2)运行以下代码,哪些对结果的描述是正确的?( )
1. public class test {
2. private static int j = 0;
3. private static boolean methodB(int k) {
4. j += k;
5. return true;
6. }
7. public static void methodA(int i) {
8. boolean b:
9. b = i < 10 | methodB (4);
10. b = i < 10 || methodB (8);
11. public static void main (String args[] } {
12. methodA (0);
13. system.out.printIn(j);
14. }
15. }
A. 程序打印: “0”
B. 程序打印: “4”
C. 程序打印: “8”
D. 程序打印: “12”
E. 代码编译报错
(3)下列说法正确的有( )
A. class中的constructor不可省略
B. constructor必须与class同名,但方法不能与class同名
C. constructor在一个对象被new时执行
D. 一个class只能定义一个constructor
(4)对以下代码,哪个描述是正确的?( )
1. class super {
2. public float getNum() {return 3.0f;}
3. }
4.
5. public class Sub extends Super {
6.
7. }
以下哪行代码放到第6行中,会导致代码编译失败?
A. Public float getNum() {return 4.0f; }
B. Public void getNum () { }
C. Public void getNum (double d) { }
D. Public double getNum (float d) {retrun 4.0f; }
(5)对以下代码,哪两个方法定义重载(Overload)了setVar 方法?( )
1. public class MethodOver {
2. private int x, y;
3. private float z;
4. public void setVar(int a, int b, float c){
5. x = a;
6. y = b;
7. z = c;
8. }
9. }
A. void setVar (int a, int b, float c){
x = a;
y = b;
z = c;
}
B. public void setVar(int a, float c, int b) {
setVar(a, b, c);
}
C. public void setVar(int a, float c, int b) {
this(a, b, c);
}
D. public void setVar(int a, float b){
x = a;
z = b;
}
E. public void setVar(int ax, int by, float cz) {
x = ax;
y = by;
z = cz;
}
(6)对以下代码,哪个说法是正确的?( )
public class Test {
public static void main(String args[]) {
class Foo {
public int i = 3;
}
Object o = (Object) new Foo();
Foo foo = (Foo) o;
System.out.println(foo.i);
}
}
A. 代码编译报错
B. 代码编译成功,运行时打印“3”
C. 代码编译成功,运行时在第6行抛出ClassCastException
D. 代码编译成功,运行时在第7行抛出 ClassCastException
注意是单选还是多选 展开
Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);
A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))
(2)运行以下代码,哪些对结果的描述是正确的?( )
1. public class test {
2. private static int j = 0;
3. private static boolean methodB(int k) {
4. j += k;
5. return true;
6. }
7. public static void methodA(int i) {
8. boolean b:
9. b = i < 10 | methodB (4);
10. b = i < 10 || methodB (8);
11. public static void main (String args[] } {
12. methodA (0);
13. system.out.printIn(j);
14. }
15. }
A. 程序打印: “0”
B. 程序打印: “4”
C. 程序打印: “8”
D. 程序打印: “12”
E. 代码编译报错
(3)下列说法正确的有( )
A. class中的constructor不可省略
B. constructor必须与class同名,但方法不能与class同名
C. constructor在一个对象被new时执行
D. 一个class只能定义一个constructor
(4)对以下代码,哪个描述是正确的?( )
1. class super {
2. public float getNum() {return 3.0f;}
3. }
4.
5. public class Sub extends Super {
6.
7. }
以下哪行代码放到第6行中,会导致代码编译失败?
A. Public float getNum() {return 4.0f; }
B. Public void getNum () { }
C. Public void getNum (double d) { }
D. Public double getNum (float d) {retrun 4.0f; }
(5)对以下代码,哪两个方法定义重载(Overload)了setVar 方法?( )
1. public class MethodOver {
2. private int x, y;
3. private float z;
4. public void setVar(int a, int b, float c){
5. x = a;
6. y = b;
7. z = c;
8. }
9. }
A. void setVar (int a, int b, float c){
x = a;
y = b;
z = c;
}
B. public void setVar(int a, float c, int b) {
setVar(a, b, c);
}
C. public void setVar(int a, float c, int b) {
this(a, b, c);
}
D. public void setVar(int a, float b){
x = a;
z = b;
}
E. public void setVar(int ax, int by, float cz) {
x = ax;
y = by;
z = cz;
}
(6)对以下代码,哪个说法是正确的?( )
public class Test {
public static void main(String args[]) {
class Foo {
public int i = 3;
}
Object o = (Object) new Foo();
Foo foo = (Foo) o;
System.out.println(foo.i);
}
}
A. 代码编译报错
B. 代码编译成功,运行时打印“3”
C. 代码编译成功,运行时在第6行抛出ClassCastException
D. 代码编译成功,运行时在第7行抛出 ClassCastException
注意是单选还是多选 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询