Write a Java program to demonstrate interface implementation in a class hierarchy
interface Vehicle { void start(); } class Car implements Vehicle { @Override public void start() { System.out.println("Car is starting"); } } class Motorcycle implements Vehicle { @Override public void start() { System.out.println("Motorcycle is starting"); } } public class Main { public static void main(String[] args) { Vehicle car = new Car(); Vehicle motorcycle = new Motorcycle(); car.start(); motorcycle.start(); } }
Car is starting Motorcycle is starting
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions