0% found this document useful (0 votes)
2 views

23# Abstraction INTERFACE Object Oriented Programming

The document provides a C# implementation of object-oriented programming concepts, specifically focusing on abstraction and interfaces. It defines an abstract class 'Animal' and various concrete classes like 'Dog', 'Cat', and 'Bird' that implement the 'IAnimal', 'ILandAnimal', and 'IAirAnimal' interfaces. The main program demonstrates the creation of these animal objects and their respective behaviors such as making sounds and walking or flying.

Uploaded by

Lesunter KLter
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)
2 views

23# Abstraction INTERFACE Object Oriented Programming

The document provides a C# implementation of object-oriented programming concepts, specifically focusing on abstraction and interfaces. It defines an abstract class 'Animal' and various concrete classes like 'Dog', 'Cat', and 'Bird' that implement the 'IAnimal', 'ILandAnimal', and 'IAirAnimal' interfaces. The main program demonstrates the creation of these animal objects and their respective behaviors such as making sounds and walking or flying.

Uploaded by

Lesunter KLter
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/ 5

23# Abstraction INTERFACE Object Oriented Programming

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{

}
}

abstract class Animal


{
public abstract void makeSound();
public void sleep()
{

}
}

class Dog : Animal


{
public override void makeSound()
{

}
}

class Cat : Animal


{
public override void makeSound()
{

}
}
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
IAnimal a = new Dog();
ILandAnimal b = new Dog();

IAnimal aa = new Cat();


ILandAnimal bb = new Cat();

IAnimal aaa = new Bird();


ILandAnimal bbb = new Bird();
IAirAnimal ccc = new Bird();

a.makeSound();
b.walk();

aa.makeSound();
bb.walk();

aaa.makeSound();
bbb.walk();
ccc.walk();
ccc.fly();
}
}

interface IAnimal
{
void makeSound();
}
interface ILandAnimal
{
void walk();
}
interface IAirAnimal:ILandAnimal
{
void fly();
}

class Dog : IAnimal,ILandAnimal


{
public void makeSound()
{
Console.WriteLine("Arf");
}
public void walk()
{
Console.WriteLine("Dog is Walking");
}
}

class Cat : IAnimal,ILandAnimal


{
public void makeSound()
{
Console.WriteLine("Meow");
}
public void walk()
{
Console.WriteLine("Cat is Walking");
}
}
class Bird : IAnimal, IAirAnimal
{
public void fly()
{
Console.WriteLine("Bird is Flying");
}
public void makeSound()
{
Console.WriteLine("Chirp");
}
public void walk()
{
Console.WriteLine("Bird is Walking");
}
}
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Dog a = new Dog();
Bird aa = new Bird();
Cat aaa = new Cat();

a.walk();
a.makeSound();

aa.fly();
aa.walk();
aa.makeSound();

aaa.walk();
aaa.makeSound();
}
}

interface IAnimal
{
void makeSound();
}
interface ILandAnimal
{
void walk();
}
interface IAirAnimal:ILandAnimal
{
void fly();
}
class Dog : IAnimal,ILandAnimal
{
public void makeSound()
{
Console.WriteLine("Arf");
}
public void walk()
{
Console.WriteLine("Dog is Walking");
}
}

class Cat : IAnimal,ILandAnimal


{
public void makeSound()
{
Console.WriteLine("Meow");
}
public void walk()
{
Console.WriteLine("Cat is Walking");
}
}

class Bird : IAnimal, IAirAnimal


{
public void fly()
{
Console.WriteLine("Bird is Flying");
}
public void makeSound()
{
Console.WriteLine("Chirp");
}
public void walk()
{
Console.WriteLine("Bird is Walking");
}
}
}

You might also like