教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

Java练习题1(有答案)(9)

来源:网络收集 时间:2026-01-29
导读: } } B: public class Test { public Test() { java.util.Date date = new java.util.Date(); } } 1、 A. 2、 B. 3、 Neither 答案 1 2 第 103题 You should add the static keyword in the place of ? in Line ____

} } B:

public class Test { public Test() { java.util.Date date = new java.util.Date(); } } 1、 A. 2、 B.

3、 Neither 答案 1 2 第 103题 You should add the static keyword in the place of ? in Line ________ in the following code: 1 public class Test {

2 private int age;

3

4 public ? int square(int n) { 5 return n * n; 6 } 7

8 public ? int getAge() { 9 } 10}

1、 in line 4 2、 in line 8

3、 in both line 4 and line 8

4、 none 答案 1 第 104题 Analyze the following code. public class Test { public static void main(String[] args) { int n = 2; xMethod(n); System.out.println(\ } void xMethod(int n) { n++; } }

1、 The code has a compile error because xMethod does not return a value.

2、 The code has a compile error because xMethod is not declared static. 3、 The code prints n is 1.

4、 The code prints n is 2.

5、 The code prints n is 3. 答案 2 第 105题 What is the printout of the second println statement in the main method? public class Foo { int i; static int s;

public static void main(String[] args) { Foo f1 = new Foo();

System.out.println(\ Foo f2 = new Foo();

System.out.println(\ Foo f3 = new Foo();

System.out.println(\ } public Foo() { i++; s++; } }

1、 f2.i is 1 f2.s is 1 2、 f2.i is 1 f2.s is 2 3、 f2.i is 2 f2.s is 2

4、 f2.i is 2 f2.s is 1 答案 2 第 106题 What is the printout of the third println statement in the main method? public class Foo { int i; static int s;

public static void main(String[] args) { Foo f1 = new Foo();

System.out.println(\ Foo f2 = new Foo();

System.out.println(\ Foo f3 = new Foo();

System.out.println(\ } public Foo() { i++; s++; } }

1、 f3.i is 1 f3.s is 1 2、 f3.i is 1 f3.s is 2 3、 f3.i is 1 f3.s is 3 4、 f3.i is 3 f3.s is 1

5、 f3.i is 3 f3.s is 3 答案 3 第 107题 Analyze the following code: public class Test {

public static void main(String args[]) { NClass nc = new NClass(); nc.t = nc.t++; } } class NClass { int t;

private NClass() { } }

1、 The program has a compilation error because the NClass class has a private constructor.

2、 The program does not compile because the parameter list of the main method is wrong.

3、 The program compiles, but has a runtime error because t has no initial value.

4、 The program compiles and runs fine. 答案 1 第 108题 Analyze the following code:

public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } …… 此处隐藏:316字,全部文档内容请下载后查看。喜欢就下载吧 ……

Java练习题1(有答案)(9).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/521351.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)