C# Program to Implement the Same Method in Multiple Classes Last Updated : 30 Sep, 2021 Comments Improve Suggest changes Like Article Like Report C# is a general-purpose programming language it is used to create mobile apps, desktop apps, websites, and games. In C#, an object is a real-world entity. Or in other words, an object is a runtime entity that is created at runtime. It is an instance of a class. In this article, Implement the same method in Multiple Classes The implementation of the same method in multiple classes can be achieved by using Interfaces. Interface in C# is just like the class it also has methods, properties, indexers, and events. But it only contains the declaration of the members and the implementation of its members will be given by the class that implements the interface implicitly or explicitly. Or we can say that all the methods which are declared inside the interface are abstract methods. It is used to achieve multiple inheritances which can't be achieved by class. Approach: Create an Interface and declare Method (i.e. greet)Now create three classes with names Class1, Class2, and Class3 and define the method greet() in all the classes.Create the class DemoClass and define the main method.In the Main method create a reference variable for Interface and initialize the reference variable by objects of class1, class2, and class3 and call the method greet(). Example 1: C# // C# program to illustrate the above concept using System; interface Interface { // Declaring Method void greet(); } // Creating classes and define the method // greet() in all classes. class Class1 : Interface { public void greet() { Console.WriteLine("Welcome Geeks"); } } class Class2 : Interface { public void greet() { Console.WriteLine("Hello Geeks"); } } class Class3 : Interface { public void greet() { Console.WriteLine("Bella Ciao Geeks"); } } class GFG{ public static void Main(String[] args) { // I is the reference variable of Interface Interface I; // Initializing the I with objects of all the // classes one by one and calling the method greet() I = new Class1(); I.greet(); I = new Class2(); I.greet(); I = new Class3(); I.greet(); } } OutputWelcome Geeks Hello Geeks Bella Ciao Geeks Example 2: C# // C# program to illustrate the above concept using System; // Interface interface Interface { // Declaring Method void greet(); } // Creating classes and define the method // greet() in all classes. class Class1 : Interface { public void greet() { Console.WriteLine("Welcome Geeks"); } } class Class2 : Interface { public void greet() { Console.WriteLine("Hello Geeks"); } } class Class3 : Interface { public void greet() { Console.WriteLine("Bella Ciao Geeks"); } } class Class4 : Interface { public void greet() { Console.WriteLine("hola geeks"); } } class Class5 : Interface { public void greet() { Console.WriteLine("welcome to geeksforgeeks"); } } class GFG{ public static void Main(String[] args) { // I is the reference variable of Interface Interface I; // Initializing the I with objects of all the // classes one by one and calling the method greet() I = new Class1(); I.greet(); I = new Class2(); I.greet(); I = new Class3(); I.greet(); I = new Class4(); I.greet(); I = new Class5(); I.greet(); } } OutputWelcome Geeks Hello Geeks Bella Ciao Geeks hola geeks welcome to geeksforgeeks Comment More infoAdvertise with us Next Article C# Program to Implement the Same Method in Multiple Classes P pulamolusaimohan Follow Improve Article Tags : Backtracking C# DSA CSharp-programs Practice Tags : Backtracking Similar Reads C# Program to Implement Multiple Interfaces in the Same Class Like a class, Interface can have methods, properties, events, and indexers as its members. But interface will contain only the declaration of the members. The implementation of interfaceâs members will be given by the class that implements the interface implicitly or explicitly. C# allows that a sin 3 min read C# | How to Implement Multiple Interfaces Having Same Method Name Like a class, Interface can have methods, properties, events, and indexers as its members. But interface will contain only the declaration of the members. The implementation of interface's members will be given by the class who implements the interface implicitly or explicitly. C# allows the impleme 4 min read C# Program to Inherit an Abstract Class and Interface in the Same Class Abstract Class is the way to achieve abstraction. It is a special class that never be instantiated directly. This class should contain at least one abstract method in it and mark by abstract keyword in the class definition. The main purpose of this class is to give a blueprint for derived classes an 3 min read C# Program to Implement an Interface in a Structure Structure is a value type and a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types. We can create a structure by using struct keyword. A structure can also hold co 2 min read How to implement method overloading in PHP ? PHP stands for Hypertext Preprocessor, it is a popular general-purpose scripting language that is mostly used in web development. It is fast, flexible, and pragmatic and the latest versions of PHP are object-oriented which means you can write classes, use inheritance, Polymorphism, Data Abstraction, 2 min read C# Program to Demonstrate Abstract Class with Multiple-level Inheritance Abstract Class is the way to achieve abstraction. It is a special class that never be instantiated directly. This class should contain at least one abstract method in it and mark by abstract keyword in the class definition. The main purpose of this class is to give a blueprint for derived classes an 3 min read C# Program to Demonstrate Interface Implementation with Multi-level Inheritance Multilevel Inheritance is the process of extending parent classes to child classes in a level. In this type of inheritance, a child class will inherit a parent class, and as well as the child class also act as the parent class to other class which is created. For example, three classes called P, Q, 3 min read Multiple Inheritance in Programming Multiple Inheritance in programming is like a family tree for your code. You have a bunch of classes, which are like different members of a family. When one class inherits from another, it's like a child inheriting traits from their parents. The child class gets all the abilities (methods) and prope 6 min read Implement Interface using Abstract Class in Java Interface contains only abstract methods that can't be instantiated and it is declared by keyword interface. A class that is declared with the abstract keyword is known as an abstract class in Java. This is a class that usually contains at least one abstract method which can't be instantiated and It 3 min read C# Program to Get the Count of Total Created Objects C# is a general-purpose programming language it is used to create mobile apps, desktop apps, websites, and games. In C#, an object is a real-world entity. Or in other words, an object is a runtime entity that is created at runtime. It is an instance of a class. In this article, we will create multip 3 min read Like