Abstractclass- An Abstract class is a class which is defines with 'abstract' keyword. There are not create instance of abstract class. To use the methods of abstract class we need to inherit it in other regular class by using semicolon(:). An abstract class can contain abstract methods and also regular methods. All abstract method have must to redefined or override in derived class because in abstract class all abstract methods only being declare, to provide its body we need to override it in derived class. Whereas all regular methods declare in abstract base class we can provide its definition in same class.
public abstract class Abstractt{
public abstract void Dog();
public void Cat()
{
Console.WriteLine('Cat cry meow meow');
}
}
public class Derivedd : Abstractt
{
public override void Dog()
{
Console.WriteLine('Dog is bark');
}
}
class AbstractTest
{
static void Main(string[] arg)
{
Derivedd dd = new Derivedd();
dd.Dog();
dd.Cat();
}
}
Output- Dog is bark
Cat cry meow meow
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Abstract class- An Abstract class is a class which is defines with 'abstract' keyword. There are not create instance of abstract class. To use the methods of abstract class we need to inherit it in other regular class by using semicolon(:). An abstract class can contain abstract methods and also regular methods. All abstract method have must to redefined or override in derived class because in abstract class all abstract methods only being declare, to provide its body we need to override it in derived class. Whereas all regular methods declare in abstract base class we can provide its definition in same class.
public abstract class Abstractt{public abstract void Dog();
public void Cat()
{
Console.WriteLine('Cat cry meow meow');
}
}
public class Derivedd : Abstractt
{
public override void Dog()
{
Console.WriteLine('Dog is bark');
}
}
class AbstractTest
{
static void Main(string[] arg)
{
Derivedd dd = new Derivedd();
dd.Dog();
dd.Cat();
}
}
Output- Dog is bark
Cat cry meow meow