Abstraction
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace HelloWorld
{
// abstract class we can't create instance for that.
abstract class Animal{
public abstract void Sound();
// normal function inside the abstract class function
public void fun(){
Console.WriteLine(":-- Normal function");
}
}
class Pig:Animal // inhert the parent class.
{
public override void Sound()
{
Console.WriteLine(":-- Overridden function");
}
}
public class Program
{
public static void Main(string[] args)
{
var obj = new Pig(); // Create object of the child class to access the parent properties.
obj.Sound();
obj.fun();
}
}
}
// another Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace HelloWorld
{
public abstract class Fruits{
public abstract void Sweets();
public abstract void Sour();
}
class Teste: Fruits {
public override void Sweets()
{
Console.WriteLine("Fruits are Sweets");
}
public override void Sour(){
Console.WriteLine("Fruits are Sour");
}
}
public class Program
{
public static void Main(string[] args)
{
Teste obj = new Teste();
obj.Sweets();
obj.Sour();
}
}
}