Hi everyone,
I'm trying to do exercise from the book I'm reading at the moment. But, I don't seem to have understood the last part of the question. I'd greatly appreciate anyone explaining the question to me. I have done all parts of the question except the last one which I am not really sure of. The bold lines that I don't really understand.
I don't want any answers please. I'd like to solve the problem myself after having a good understanding of what I should be doing and someone explains the part that I don't understand.
Here is the question:
Exercise 8: (4) 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 called Soup1
class Soup1 {
private Soup1(){ }
public static Soup1 makeSoup(){
return new Soup1();
}
}
// Class called Soup2
class Soup2 {
private Soup2(){ }
private static Soup2 ps1 = new Soup2();
public static Soup2 access(){
return ps1;
}
public void f(){ }
}
// Class called lunch
public class lunch {
void testStatic(){
Soup1 soup = Soup1.makeSoup();
}
void testSingleton(){
Soup2.access().f();
}
}
// Class called ConnectionManager
class ConnectionManager {
Object[] connecter = new Object[5];
private ConnectionManager(){
}
static ConnectionManager connecter(){
return new ConnectionManager();
}
}
Thanks,