Slide 16
Slide 16 text
jgs
Javier Gonzalez-Sanchez | CSC 308 | Winter 2023 | 16
class MainApp {
public static void Main(String []a){
// Constructor is protected -- cannot use new
Singleton s1 = Singleton.getInstance();
Singleton s2 = Singleton.getInstance();
// Test for same instance
if (s1 == s2){
// true - Objects are the same instance
}
}
}
Singleton