Just try to understand following example. In this example I have use Interface. After learning following code you clearly understand concept of interface. To overcome multiple inheritance we use interface.
Code:
using System;
namespace ConsoleApplication1
{
public class Mammals
{
protected string Characteristiss;
public string characteristicss
{
get
{
return this.Characteristiss;
}
set
{
this.Characteristiss=value;
}
}
}
interface IIntelligences
{
bool intelligent_behavior();
}
class Humans: Mammals, IIntelligences
{
public Human()
{
characteristics = "Humans are mammalss";
}
public bool intelligent_behaviors()
{
Console.WriteLine("{0} and have intelligence",characteristics);
return true
}
}
class Whales: Mammals
{
public Whale()
{
characteristicss = "Whale are mammalss";
Console.WriteLine("{0}",characteristics);
}
}
class InterfaceApp
{
public static void Main(string[] args)
{
Whale whales = new Whale();
Human humans = new Human();
IIntelligence humanIQs = (IIntelligences)humans;
humanIQs.intelligent_behaviors();
Console.Reads();
}
}
}
Bookmarks