Home » .Net

Abstract properties in C#



In this article, we will learn about Abstract properties in C# with Example.
Submitted by IncludeHelp, on August 06, 2018

C# Abstract properties

An abstract may contain some abstract properties. That can be implemented in derived class. Here we use abstract and override keywords.

Example:

using System;
using System.Collections;

namespace ConsoleApplication1
{
    abstract class HUMAN
    {
        public abstract int ID
        {
            get;
            set;
        }

        public abstract string NAME
        {
            get;
            set;
        }

        public abstract int SALARY
        {
            get;
            set;
        }
    }

    class EMPLOYEE:HUMAN
    {
        private int     EMP_ID      ;
        private string  EMP_NAME    ;
        private int     EMP_SALARY  ;

        public override int ID
        {
            get
            {
                return EMP_ID;
            }

            set
            {
                EMP_ID = value;
            }
        }

        public override string NAME
        {
            get
            {
                return EMP_NAME;
            }

            set
            {
                EMP_NAME = value;
            }
        }

        public override int SALARY
        {
            get
            {
                return EMP_SALARY;
            }
            set
            {
                EMP_SALARY = value;
            }
        }

    }

    class Program
    {
        static void Main()
        {
            EMPLOYEE E = new EMPLOYEE();

            E.ID   = 101;
            E.NAME = "Duggu Pandit";
            E.SALARY = 1000000;

            Console.WriteLine("ID     : " + E.ID);
            Console.WriteLine("NAME   : " + E.NAME);
            Console.WriteLine("SALARY : " + E.SALARY);

        }
    }
}

Output

    ID		: 101
    NAME	: Duggu Pandit
    SALARY	: 1000000





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Quick links
Latest articles, Internship, Members
New...
Coding problems, Algorithms, Discrete Mathematics, Big data
Languages
C, C++, C++ STL, Java, Data Structure, C#.Net, Android, Kotlin, SQL
Web
PHP, Python, JavaScript, CSS, Ajax, Node.js, Web prog.
Programs
C, C++, DS, Java, C#, Python
Aptitude
C, C++, Java, DBMS
Interview
C, Embedded C, Java, SEO, HR
CS Subjects
CS Basics O.S. Networks DBMS Embedded Systems Cloud Computing Machine learning CS Organizations Linux DOS
More...
Articles, Puzzles, News/Updates


Recommended posts
C Tips & Tricks, C++ Tips & Tricks
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distros of 2018
C programming optimization techniques
Differences b/w C & Embedded C?
Embedded C Interview Q. & A.
C programming tips for Embedded Development
Basic rules of writing a C program
Important points (rules) to remember while writing C/C++ program
Top 5 Websites for solving programming challenges
Read more...


Others...
Computer G.K. (MCQ)
Most viewed pages...
Categories...



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.