Use of abstraction - C#.NET

Explain the use of abstraction with an example using C#.NET.

Abstraction is used to create a common set of methods that might have different specific implementations by subclasses. Abstract class cannot be instantiated and consists of abstract methods without any implementations. Classes inheriting from abstract class must implement all the methods in abstract class.
Public abstract class Shape
{
   Private float _area;
   Public Float Area
   {
       Get{return _area;}
       Set{_area=value;}
   }
   Public abstract void CalculateArea();

   Class Rect:Shape
   {
       Private float _height;
       Private float _width;
       Public Rect(float height, float width)
       {
            _height = height;
           _width = width;
       }
       Public Float Height
       {
           Get{return _height}
           Set{_height=value;}
       }
       Public Float Width
       {
           Get{return _width}
           Set{_width=value;}
       }
       Public override void CalculateArea()
       {
           This.Area=_height*_width;
       }
   }
}
Use of encapsulation - C#.NET
Use of encapsulation - Encapsulation hides the internal state and behavior of an object...
Differentiate between instance data and class data - C#.NET
Differentiate between instance data and class data - Class data in terms of static class is the data that particular class holds in its structure...
Significance of static method - C#.NET
Explain the significance of static method - Static methods are used when we want only one copy of that method to perform action and remain active at a single point in time...
Post your comment