题目和另一种解法.txt
来自「thinking in java 第三版 第五章 11题 答案」· 文本 代码 · 共 21 行
TXT
21 行
. Following the form of the example Lunch.java, create a class called ConnectionManager that manages a fixed array of Connection objects. The client programmer must not be able to explicitly create Connection objects, but can only get them via a static method in ConnectionManager. When the ConnectionManager runs out of objects, it returns a null reference. Test the classes in main(?).
class Connection{
private Connection(){}
public static Connection Make(){
return new Connection();
}
}
public class ConnectionManager{
public static Connection[] func() {
Connection[] n1={Connection.Make(),Connection.Make(),Connection.Make()};
return n1;
}
public static void main(String[] args){
System.out.print("the length of the array is:");
System.out.println(func().length);
System.out.println("a fixed array of Connection objects is created");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?