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

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

来源:网络收集 时间:2026-01-29
导读: 1、 The variable t is not initialized and therefore causes errors. 2、 The variable t is private and therefore cannot be accessed in the main method. 3、 t is non-static and it cannot be referenced i

1、 The variable t is not initialized and therefore causes errors. 2、 The variable t is private and therefore cannot be accessed in the main method.

3、 t is non-static and it cannot be referenced in a static context in the main method.

4、 The variable x is not initialized and therefore causes errors. 5、 The program compiles and runs fine. 答案 3 第 109题 Analyze the following code and choose the best answer: public

class

Foo

{ private int x;

public static void main(String[] args) { Foo foo = new Foo(); System.out.println(foo.x); } }

1、 Since x is private, it cannot be accessed from an object foo.

2、 Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code.

3、 Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code.

4、 You cannot create a self-referenced object; that is, foo is created inside the class Foo. 答案 3 第 110题 When invoking a method with an object argument, ___________ is passed. 1、 the contents of the object 2、 a copy of the object 3、 the reference of the object

4、 the object is copied, then the reference of the copied object 答案 3 第 111题 What is the value of myCount.count displayed? public class Test {

public static void main(String[] args) { Count myCount = new Count(); int times = 0; for (int i=0; i<100; i++) increment(myCount, times); System.out.println(

\ System.out.println(\ } public static void increment(Count c, int times) { c.count++; times++; } } class Count { int count; Count(int c) { count = c; } Count() { count = 1; } } 1、 101 2、 100

3、 99 4、 98 答案 1 第 112题 What is the value of times displayed? public class Test {

public static void main(String[] args) { Count myCount = new Count(); int times = 0; for (int i=0; i<100; i++) increment(myCount, times);

Java练习题1(有答案)(10).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)