Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | Inheritance in interfaces
Next article icon

C# | Inheritance in interfaces

Last Updated : 23 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

C# allows the user to inherit one interface into another interface. When a class implements the inherited interface then it must provide the implementation of all the members that are defined within the interface inheritance chain.
Important Points:  

  • If a class implements an interface, then it is necessary to implement all the method that defined by that interface including the base interface methods. Otherwise, the compiler throws an error.
  • If both derived interface and base interface declares the same member then the base interface member name is hidden by the derived interface member name.


Syntax:

// declaring an interface
access_modifier interface interface_name
{
// Your code
}

// inheriting the interface
access_modifier interface interface_name : interface_name
{
// Your code
}


Example 1:

CSharp
// C# program to illustrate the concept // of inheritance in interface using System;  // declaring an interface public interface A {          // method of interface     void mymethod1();     void mymethod2(); }  // The methods of interface A  // is inherited into interface B public interface B : A {          // method of interface B     void mymethod3(); }   // Below class is inheriting // only interface B // This class must  // implement both interfaces class Geeks : B {          // implementing the method     // of interface A     public void mymethod1()     {         Console.WriteLine("Implement method 1");     }          // Implement the method      // of interface A     public void mymethod2()     {         Console.WriteLine("Implement method 2");     }          // Implement the method     // of interface B     public void mymethod3()     {         Console.WriteLine("Implement method 3");     } }  // Driver Class class GFG {      // Main method     static void Main(String []args)     {                  // creating the object         // class of Geeks         Geeks obj = new Geeks();                  // calling the method          // using object 'obj'         obj.mymethod1();         obj.mymethod2();         obj.mymethod3();     } } 

Output
Implement method 1 Implement method 2 Implement method 3

Example 2:

CSharp
// C# program to illustrate the concept // of inheritance in the interface using System;  // declaring an interface public interface Votes  {          // method of interface      void vote_no(int a); }  // The methods of interface Votes // is inherited into interface Details public interface Details : Votes  {          // method of interface Details     void detailsofauthor(string n, int p); }  // Below class is inheriting  // the interface Details // This class must implement  // the methods of both interface // i.e. Votes and Details class TechnicalScriptWriter : Details  {      // implementing the method      // of interface Votes     public void vote_no(int a)     {         Console.WriteLine("Total number of votes is: {0}", a);     }          // implementing the method      // of interface Details      public void detailsofauthor(string n, int p)     {         Console.WriteLine("Name of the author is: {0}", n);                  Console.WriteLine("Total number of published" +                                  " article is: {0}", p);     } }  // Driver Class class GFG {      // Main method     static void Main()     {          // Creating the objects of          // TechinalScriptWriter class         TechnicalScriptWriter obj = new TechnicalScriptWriter();                  // calling the methods by passing         // the required values         obj.vote_no(470045);         obj.detailsofauthor("Siya", 98);     } } 

Output
Total number of votes is: 470045 Name of the author is: Siya Total number of published article is: 98 

Next Article
C# | Inheritance in interfaces

A

ankita_saini
Improve
Article Tags :
  • C#
  • CSharp-OOP

Similar Reads

    C# | Multiple inheritance using interfaces
    Introduction:Multiple inheritance refers to the ability of a class to inherit from multiple base classes. C# does not support multiple inheritance of classes, but it does supportmultiple inheritance using interfaces. An interface is a collection of abstract methods that a class can implement to prov
    7 min read
    C# | Multilevel Inheritance
    Introduction: In object-oriented programming, inheritance is the ability to create new classes that are derived from existing classes, known as base or parent classes. Inheritance allows the derived classes to inherit properties and methods of the base classes and to add new features or functionalit
    7 min read
    C# Inheritance
    Inheritance is a fundamental concept in object-oriented programming that allows a child class to inherit the properties from the superclass. The new class inherits the properties and methods of the existing class and can also add new properties and methods of its own. Inheritance promotes code reuse
    6 min read
    C# | Explicit Interface Implementation
    An Interface is a collection of loosely bound items that have a common functionality or attributes. Interfaces contain method signatures, properties, events etc. Interfaces are used so that one class or struct can implement multiple behaviors. C# doesn't support the concept of Multiple Inheritance b
    4 min read
    C# Interface
    An interface is defined using the interface keyword, similar to a class. An Interface is a blueprint that outlines a group of methods, properties, events, or indexers that a class or struct must implement. Unlike classes, it contains only the declaration of the members. The implementation of the int
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences