You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
660 B
23 lines
660 B
3 years ago
|
package patronSingleton;
|
||
|
|
||
|
public class Main {
|
||
|
|
||
|
public static void main(String [] args) {
|
||
|
|
||
|
Singleton s = Singleton.getSingleton(); //Permitido
|
||
|
|
||
|
Singleton s2 = Singleton.getSingleton(); //No permitido
|
||
|
|
||
|
//otra opcion es la inicializacion bajo demanda, en la que el
|
||
|
//singleton se instancia solo, y el mismo controla que no pueda
|
||
|
//haber mas.
|
||
|
|
||
|
|
||
|
Singleton1 sin1 = Singleton1.getInstancia();
|
||
|
sin1.mostrarMensaje();
|
||
|
// Singleton1 sin2 = new Singleton1();
|
||
|
//Esta linea da error por no estar visible el constructor.
|
||
|
}
|
||
|
|
||
|
}
|