第六章
第六章课后练习题
CHNMSCS
分享是一种快乐,
脚踏实地,仰望星空
展开
-
Java 习题 (57) **
题目: 效仿示例Lunch.java 的形式,创建一个名为ConnectionManager的类,该类管理一个元素为Connection对象的固定数组。客户端程序员不能直接创建Connection对象,而只能通过ConnectionManager中的某个static方法来获取它们。当ConnectionManager之中不再有对象时,它会返回null引用。在main()之中检测这些类。 解答: 先放Lunch.java代码: class Soup1 { private Soup1() {} publi原创 2020-08-01 10:49:41 · 351 阅读 · 0 评论 -
Java 习题 (56)
题目: 根据描述access和widget的代码片段创建类库。在某个不属于access类库的类中创建一个Widget实例。 Create the library according to the code fragments describing access and Widget. Create a Widget in a class that is not part of the access package 解答: 没使用在access package下创建类,但是下面的代码效果是一样的 packag原创 2020-08-01 09:07:00 · 163 阅读 · 0 评论 -
Java 习题 (55)
题目: 创建一个带有protected数据的类。运用在第一个类中处理protected数据的方法在相同的文件中创建第二个类。 Created a class with protected data. Create a second class in the same file with a method that manipulates the protected data in the first class. 解答: package six; class one { protected int原创 2020-08-01 07:48:06 · 185 阅读 · 0 评论 -
Java 习题 (54)
题目: 创建一个带有public, private, protected和包访问权限域以及方法成员的类。创建该类的一个对象,看看在你试图调用所有类成员时,会得到什么类型的编译信息。请注意,处于同一个目录中的所有类都是默认包的一部分。 Create a class with public, private, protected, and package-access fields and method members. Create an object of this class and see what k原创 2020-08-01 07:33:23 · 237 阅读 · 0 评论 -
Java 习题 (53)
题目: 展示protected方法具有包访问权限,但是它仍旧不是public的。 Show that protected methods have package access but are not public. 解答: 先是在同一个package 下 package six; public class fourExercise { protected static void greeting() { System.out.println("This is the fourEx原创 2020-08-01 06:27:34 · 121 阅读 · 0 评论 -
Java 习题 (52)
题目: 创建两个包:debug 和 debugoff, 它们都包含一个相同的类,该类有一个debug()方法。第一个版本显示发送给控制台的String 参数,而第二个版本什么也不做。使用静态import语句将该类导入到一个测试程序中,并示范条件编译效果。 Create two packages: debug and debugoff, containing an identical class with a debug() method. The first version displays its Str原创 2020-08-01 02:36:53 · 161 阅读 · 0 评论 -
Java 习题 (51)
题目: 在某个包中创建一个类,在这个类所处的包的外部创建该类的一个实例。 Create a class in a package. Create an instance of your class outside of that package. 解答: package six.First; public class firstExercise { firstExercise() { System.out.println("This is the default construct原创 2020-08-01 01:05:36 · 162 阅读 · 0 评论