Write a Java program to demonstrate the use of an interface with a static factory method
public class InterfaceWithStaticFactoryMethodDemo { public static void main(String[] args) { MyInterface obj = MyInterface.createInstance();// Use the static factory method to create an instance obj.doSomething(); // Call the method on the created instance } } interface MyInterface// Define an interface with a static factory method { void doSomething(); static MyInterface createInstance() // Static factory method to create instances { return new MyConcreteClass(); } } class MyConcreteClass implements MyInterface// Create a concrete class that implements the interface { @Override public void doSomething() { System.out.println("MyConcreteClass is doing something"); } }
MyConcreteClass is doing something
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions