0% found this document useful (0 votes)
28 views2 pages

Interface - I Can Move

Uploaded by

Justin Miranda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Interface - I Can Move

Uploaded by

Justin Miranda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

namespace Interfaces
{
class CalculatingShapes
{
static void Main(string[] args)
{
Console.WriteLine("\t\t\t\t Interface and Abstract ");

Cat cat = new Cat("Jeremy");

cat.Run();

cat.Drink();
cat.Eat();

Console.ReadLine();

}
}
interface ICanMove
{

// Methods
void Run();

void Back();

void GetVelocity();

}
interface ICanEat
{
// Methods
void Eat();

}
interface ICanDrink
{

// Methods

void Drink();

}
public abstract class Animal : ICanMove
{

// Methods
public abstract void Run();

public void Back()


{
throw new NotImplementedException();
}

public void GetVelocity()


{
throw new NotImplementedException();
}
}

public class Cat : Animal, ICanEat, ICanDrink


{
// field
private string name;

public Cat(string n)
{
name = n;
}
public string GetName
{
get
{ return name;
}
set
{
if (value == null)
{
throw new ArgumentNullException("Can't be null");
}
else
{
this.name = value;
}
}
}

public override void Run()


{
Console.WriteLine("{0} is a cat and it can run fast.\n", name);
}

public void Drink()


{
Console.WriteLine("{0} love to drink milk.\n", name);
}
public void Eat()
{
Console.WriteLine("It also loves to eat a lot.\n");
}

}
}

You might also like