A singleton is a class that only ever has one single instance. For more information on the Singleton design pattern, please refer to the Singleton topic in the Design Patterns tag.
The program demonstrates the implementation of a Singleton class in Java. The Singleton pattern ensures that only one instance of a class can be created throughout the entire application lifecycle.
//Singleton Class in Java class ABC { static ABC obj =null; private ABC(){} public static ABC getInstance() { if(obj==null) obj=new ABC(); return obj; } void display() { System.out.println("I am Display"); } } public class Singleton { public static void main(String[] args) { ABC o=ABC.getInstance(); o.display(); } }
I am DisplayTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions