Monday, May 14, 2012

What is Interface and how to use it in asp.net

In object oriented programming the code can be defined under another container known as interface.which can be defined with only abstract methods in it.Inheritance is organised as implementation and interface inheritance .Implementation inheritance is achieved through classes which is always single.
Interface inheritance is achieved through an interface which is multiple .Multiple inheritance is supported through interfaces under java and .net languages
[<modifiers>]interface<name>
{
<abstract members>;
}
-->An interface cannot contain variables in it
-->members of an interface by default public
-->method under interface are by default abstract
-->while implementing the methods of an interface under the class no need of using the override keyword
-->An interface can inherit another interface


Interface Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication10
{
class Program:bhaskar1,bhaskar2
{
static void Main(string[] args)
{
Console.WriteLine("Create my first interface");
Program p = new Program();
p.printbhaskar1();
p.printbhaskar2();
}
public void printbhaskar1()
{
Console.WriteLine("FirstMethod Implementation");
}
public void printbhaskar2()
{
Console.WriteLine("Second Method Implementation");
Console.ReadKey();
}
}
interface bhaskar1
{
void printbhaskar1();
}
interface bhaskar2
{
void printbhaskar2();
}
}
Post a Comment

Bel