ABSTRECT CLASS IN C# PROGRAMING


What is Abstrect class


An abstract class is a special type of class that cannot be instantiated. An abstract class is designed to be inherited by sub classes that either implement or override its methods. In other words, abstract classes are either partially implemented or not implemented at all. You can have functionality in your abstract class—the methods in an abstract class can be both abstract and concrete. An abstract class can have constructors—this is one major difference between an abstract class and an interface. You can take advantage of abstract classes to design components and specify some level of common functionality that must be implemented by derived classes.
  •  Code of Abstrect class example 



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

namespace abstrectClass
{

    abstract class person
    {
        public string Firstname;
        public string Lastname;
        public int age;
        public long number;
        public abstract void printdetail();
    }
    class student : person
    {
        public int rollno;
        public int fees;
        public override void  printdetail()
        {
            string name = "First name  :" + this.Firstname + "  Last Name  :" + this.Lastname;
            
            Console.WriteLine(name);
            Console.WriteLine("student Age   :"+this.age);
            Console.WriteLine("student Phone number :"+this.number);
            Console.WriteLine("Student rollno :"+this.rollno);
            Console.WriteLine("student fees  :"+ this.fees);
        }

    }
    class teacher :person
    {
        public string que;
        public double salary;

        public override void printdetail()
        {
            string name = "First name  :" + this.Firstname + "Last Name  :" + this.Lastname;


            Console.WriteLine(name);
            Console.WriteLine("student Age   :"+ this.age);
            Console.WriteLine("student Phone number :"+this.number);
            Console.WriteLine("quailfication "+this.que);
            Console.WriteLine("Teacher salary :"+this.salary);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            student obj = new student();
            obj.Firstname = "Bhavya";
            obj.Lastname = "Patel";
            obj.age = 22;
            obj.number = 9726;
            obj.rollno = 47;
            obj.fees = 2000;
            obj.printdetail();

            teacher tch = new teacher();
            tch.Firstname = "Ram";
            tch.Lastname = "srma";
            tch.age = 38;
            tch.number = 9856;
            tch.que = "teacher";
            tch.salary = 50000;

            Console.Read();
        }
        
    }
    
}

Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls