Write a Java program to demonstrate the use of an interface with a default method for logging
interface Logger { void log(String message); default void logError(String errorMessage) { log("Error: " + errorMessage); } } class ConsoleLogger implements Logger { @Override public void log(String message) { System.out.println("Log : " + message); } } public class Main { public static void main(String[] args) { Logger logger = new ConsoleLogger(); logger.log("Info message"); logger.logError("Something went wrong"); } }
Log : Info message Log : Error: Something went wrong
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions