You must Sign In to post a response.
  • Category: .NET

    Abstarct function and abstract class

    Abstract Methods--> A method without Method Body is known as abstract method. it contains only declaration of the method. If we want to define a abstract method we need to use abstract modifier on that method.

    Abstract Function--> A function which contains only Declaration/signature and doesn't contain Implementation/Body/Definition is known as Abstract function. To make any function as abstract use abstract keyword. An abstract function should be terminated. overridding of an abstract function is compulsory.

    Abstract Class--> A class which contains one or more abstract function is known as an abstract class.To make any Class as abstract use abstract keyword. It's Compulsory to create/ derive a new class from an abstract class in order to provide functionality to its abstract functions.
    An abstract class can contain Non-abstarct functions. An abstract class can contain all member of a class. By default abstract class functions are not treated as public and abstract.

    Program for abstract class---------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Abstract
    abstract class Employee
    protected int EmpId, EAge;
    protected string EName, EAddress;
    public abstract void GetEmpData();
    public virtual void DisplayEmpData()
    Console.Write("Enter Employee Details");
    this.EmpId = Convert.ToInt32(Console.ReadLine());
    this.EName = Console.ReadLine();
    this.EAddress = Console.ReadLine();
    this.EAge = Convert.ToInt32(Console.ReadLine());
    public virtual void DispalyEmpData()
    Console.WriteLine("Employee Id is :-" + this.EmpId);
    Console.WriteLine("Employee Name is :-" + this.EName);
    Console.WriteLine("Employee Address is :-" + this.EAddress);
    Console.WriteLine("Employee Age is :-" + this.EAge);
    class Manager : Employee
    double Bonus, CA;
    public override void GetEmpData()
    Console.Write("Enter Managers Details :-");
    EmpId = Convert.ToInt32(Console.ReadLine());
    EName = Console.ReadLine();
    Bonus = Convert.ToDouble(Console.ReadLine());
    CA = Convert.ToDouble(Console.ReadLine());
    public override void DispalyEmpData()
    Console.WriteLine("Manager Id is" + EmpId);
    Console.WriteLine("Manager Name is" + EName);
    Console.WriteLine("Manager Bonus is" + Bonus);
    Console.WriteLine("Manager CA is" + CA);
    class Abstract
    static void Main(string[] args)
    Manager Obj1 = new Manager();

    output for this program is----

    Enter manager Detail is-- 10
    Manager Id is:- 10
    Manager Name is:- ravi
    Manager Bonus is:- 15000
    Manager CA is:- 25000
  • #765718

    This is not the place to post such type of articles, please use Articles section for posting articles in our forum.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #765727
    This is the forum section, do you have any question or query ? or if you want to publish your something. If yes then you can write an article on such aspect and deploy it in our article section, if your article is having quality then you can applicable for reward and cash.
    You can make money from this site by posting original and quality articles that comply with Google AdSense policies.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

Sign In to post your comments