In this post we will discuss on Abstract Class, Static class and Generic class.
Abstract class:
Abstract class is a class that must be inherited and have the methods of overloading. We can't inherit the abstract to some other class, by creating object to the abstract class we can use the members in other class.
Syntax:
abstract class abClass
{
}
Abstract method:
Abstract method we define under the abstract class. Abstract method contains only definition. Body (logic/code) we create in the derived class by overriding.
An abstract class can contain both abstract and non abstract methods.
Syntax:
public abstract return type methodname()
{
}
Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractClass
{
abstract class abClass
{
public void abMethod1()
{
Console.WriteLine("I'm a non abstract method under abClass");
//Console.Read();
}
public abstract void abMethod2();
}
class Program : abClass
{
public override void abMethod2()
{
Console.WriteLine("I'm a abstract method under abClass");
Console.Read();
}
public void ccProgram()
{
abMethod1();
}
static void Main(string[] args)
{
Program ab = new Program();
ab.ccProgram();
ab.abMethod2();
}
}
}
if we not override the abstract class in the derived class, we get the compile time error as below
Note:
Abstract method should public.




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery


No comments:
Post a Comment