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

22# Abstraction Abstract Classes Object Oriented Programming

The document presents a C# program demonstrating object-oriented programming concepts, specifically abstraction and abstract classes. It defines an abstract class 'Animal' with derived classes 'Dog' and 'Cat', each implementing the 'makeSound' method. The main program creates instances of these classes and invokes their methods to showcase their functionality.

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

22# Abstraction Abstract Classes Object Oriented Programming

The document presents a C# program demonstrating object-oriented programming concepts, specifically abstraction and abstract classes. It defines an abstract class 'Animal' with derived classes 'Dog' and 'Cat', each implementing the 'makeSound' method. The main program creates instances of these classes and invokes their methods to showcase their functionality.

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/ 3

22# Abstraction Abstract Classes Object Oriented Programming

using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Animal d = new Dog("Ginger",2,"Mini Pincher");
Animal c = new Cat("Monkey",3);
d.makeSound();
d.sleep();

c.makeSound();
c.sleep();
}
}

abstract class Animal


{
string name { get; set; }
int age { get; set; }

protected Animal(string name, int age)


{
this.name = name;
this.age = age;
}
public abstract void makeSound();
public void sleep()
{
Console.WriteLine(" Zzzzz");
}
}

class Dog : Animal


{
string breed { get; set; }

public Dog(string name, int age,string breed) : base(name, age)


{
this.breed = breed;
}

public override void makeSound()


{
Console.WriteLine("Arf!");
}
}

class Cat : Animal


{
public Cat(string name, int age) : base(name, age){}
public override void makeSound()
{
Console.WriteLine("Meow!");
}
}
}

You might also like