Create a Java program to demonstrate method overriding with a subclass that overrides a method from an interface
The code defines an interface Printable with a single method print, and a class Printer that implements the Printable interface by providing an implementation for the print method. Then, in the Main class, you create an instance of the Printer class and assign it to a Printable reference, demonstrating polymorphism. Finally, you call the print method on the Printable reference, which invokes the print method in the Printer class. Here's an explanation of the code:
interface Printable { void print(); } class Printer implements Printable { @Override public void print() { System.out.println("Printing..."); } } public class Main { public static void main(String[] args) { Printable printer = new Printer(); printer.print(); } }
Printing...
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions