Use this space to put some text. Update this text in HTML

468x60 banner ad

Advertise with Us

Powered by Blogger.

Tuesday 16 February 2016

abstraction-in-c-sharp-with-example

Abstraction 
To reduce and remove the complexity of programming language we use abstraction.
Each real world entity has behavior and functionality. Behavior should be hidden and functionality should be exposing. 

 

Example-


1.      Do you know the inner details of the Monitor of your PC? What happen when you switch ON Monitor? Does this matter to you what is happening inside the Monitor? No Right, Important thing for you is weather Monitor is ON or NOT. 


2.      When you change the gear of your vehicle are you really concern about the inner details of your vehicle engine? No but what matter to you is that Gear must get changed that’s it.


Example of Abstraction:
using System;

using System.Collections.Generic;

using System.Linq;

namespace abstarction
{
    public abstract class college
    {
        public abstract void BTech();
        public abstract void MBA();
    }
    public class Amity : college
    {
        public override void BTech()
        {
            Console.WriteLine("Amity BTech Fee 81000/-");
        }
        public override void MBA()
        {
            Console.WriteLine("Amity MBA Fee 210000/-");
        }
    }
    public class BhartiBidyapeeth : college
    {
        public override void BTech()
        {
            Console.WriteLine("Bharti-Bidyapeeth BTech Fee 41000/-");
        }
      public override void MBA()
        {
            Console.WriteLine("Bharti-Bidyapeeth MBA Fee 110000/-");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Amity ObjAmity = new Amity();
            ObjAmity.BTech();
            ObjAmity.MBA();
            BhartiBidyapeeth ObjBhartiBidyapeeth = new BhartiBidyapeeth();
            ObjBhartiBidyapeeth .BTech();
            ObjBhartiBidyapeeth.MBA();
            Console.ReadLine();
}
Output-
  Amity BTech Fee 81000/-
  Amity MBA Fee 210000/-
  Bharti-Bidyapeeth BTech Fee 41000/-
Bharti-Bidyapeeth MBA Fee 110000/-

Explanation :-

Ø  From above example we have make one abstract class college and two abstract methods Btech and MBA. Amity and Bharti-Bidyapeeth both are override university course fee.
Ø  College course common for both Amity and Bharti-Bidyapeeth so university method BTech and MBA is abstract.
Ø  Amity and Bharti-Bidyapeeth inherited abstract method so college method must be override here.

No comments :

Post a Comment

Ask a Question?