Last active
December 1, 2023 20:25
-
-
Save isaacssemugenyi/775eed99b8f1fa11ea9570bc3f52fa1b to your computer and use it in GitHub Desktop.
Java Singleton Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Singleton { | |
private static Singleton instance; | |
private String name; | |
private int age; | |
private Singleton(String name, int age){ | |
this.name = name; | |
this.age = age; | |
} | |
public static Singleton getInstance(String name, int age){ | |
if (instance == null) { | |
instance = new Singleton(name, age); | |
} | |
return instance; | |
} | |
public String getName(){ return this.name; } | |
public int getAge(){ return this.age; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment