C# OOP-interface


An interface can be used as a template for other classes. Its purpose is to be inherited. It sounds like an abstract class. However, in the interface, you cannot declare variables unless they are constants. In addition, methods can be declared, but those are without bodies. The bodies of the methods need to be put in the classes that implement the interface.


 class Dog : Animal //implement Animal interface


        private string dogName;

        private int numberOflegs;

        public void setdogName(string name) { dogName = name; }


        public string getdogName() { return dogName; }

        public void setnumberOflegs(int n) { numberOflegs = n; }


        public int getnumberOflegs() { return numberOflegs; }




interface Animal


   void setnumberOflegs(int n);

   int getnumberOflegs();



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.