Java Program to Implement the Method of an Interface in Multiple Classes

You are currently viewing Java Program to Implement the Method of an Interface in Multiple Classes

Java program to implement the method of an interface in multiple classes

// Java program to implement the method of an 
// interface in multiple classes

interface Inf {
  //public and abstract
  void sayHello();
}

class Sample1 implements Inf {
  public void sayHello() {
    System.out.println("Sample1:Hello World");
  }
}

class Sample2 implements Inf {
  public void sayHello() {
    System.out.println("Sample2:Hello World");
  }
}

class Sample3 implements Inf {
  public void sayHello() {
    System.out.println("Sample3:Hello World");
  }
}

public class Main {
  public static void main(String[] args) {
    Sample1 S1 = new Sample1();
    Sample2 S2 = new Sample2();
    Sample3 S3 = new Sample3();

    S1.sayHello();
    S2.sayHello();
    S3.sayHello();
  }
}

Output

Sample1:Hello World
Sample2:Hello World
Sample3:Hello World

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply