Skip to content

Instantly share code, notes, and snippets.

@isaacssemugenyi
Last active December 1, 2023 20:25
Show Gist options
  • Save isaacssemugenyi/775eed99b8f1fa11ea9570bc3f52fa1b to your computer and use it in GitHub Desktop.
Save isaacssemugenyi/775eed99b8f1fa11ea9570bc3f52fa1b to your computer and use it in GitHub Desktop.
Java Singleton Pattern
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