Home » Programming » C# » Story Details
Printable Version

Abstract Class in C#

by Manish Tewatia on Nov 28, 2011

In this story, we will learn about abstract classes in C#.
Comments: 0    Views: 698

Abstract Class 

We do not create a instance of the abstract class in C#. Abstract class cannot provide  implementations. Abstract class may contain non-final variables. Abstract class defines few or none of the methods.Abstract classes can have implementations for some of its members. A abstract class can have the usual flavors of class members like private, protected.

A abstract class should be extended using keyword “extends". A abstract class also cannot be instantiated, but can be invoked if a main() exists. To use the definitions defined in the abstract class the child class inherits from the abstract class and then instances of the Child class may be easily created. Abstract class is mainly used to if you want to derive show the hierarchical information. Abstract class is also support data hiding. We have mainly used the abstract class code re-usability process. We have not create the object of the abstract class because abstract class is in incomplete. The one a most important things is if you create a abstract class so the methods of abstract class is always abstract.

Code Sample

using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abtract_Class
{
    abstract class manishroom
    {
        abstract public int area();
    }
    class Squ : manishroom
    {
        int s = 0;
        public Squ(int n)
        {
            s = n;
        }
        public override int area()
        {
            return s * s;
        }
        static void Main()
        {
            Squ sq = new Squ(15);
            Console.WriteLine("Area of the manishroom= {0} ", sq.area());
            Console.ReadLine();
        }
    }
}

Output:

123.gif

Summary 

Now in example we create a abstract class that name is "manishroom". The name of abstract methods is "area". Now through a abstract class we simply so the area. Now we see abstract class only contain a definition and derive all method which class that is inherit abstract class. In last simple create a object of a class and show the  functionality of the class.

References

Here are some good references on abstract class and related resources.

Abstract Class Resources in C# 

   

Post a Comment
*
DevExpress PowerBuilder Web Development Windows Development Languages Software Engineering Databases
iPhone Architecture Secutiry UML & Modeling Operating Systems Networking Testing
Graphics Design Project Management Hardware Open Source Games Development Business Intelligence Visual Studio LightSwitch 2011
MonoDevelop Visual Studio 2010 ASP.NET HTML, DHTML XML PHP JavaScript
Silverlight Web Services WCF Windows Forms WPF Windows Services Dynamic Link Libraries
ActiveX COM, DCOM, ATL C# VB.NET C++ F# Java
Pascal SQL Server Oracle DB2 MS-Access Windows Servers Windows
Linux Unix SAP LINQ .NET Framework ADO.NET Reporting
Crystal Reports SQL Server Reporting Services Igenda Reports Active Reports Adobe Fireworks Arrays & Collections Hosting
Future Trends Android Windows Phone Smart Devices Business M&A Investment & Funding
Web Browsers Internet Explorer Firefox Safari Common Entrepreneurs Students
Consulting Wiki Gadgets MobileMe iCloud iOS Social Media
Facebook Twitter LinkedIn Google+ Microsoft Kinect XBox
Wii Playstation DirectX i OS OS X CIO, CTO, CEO Windows 8
Web Design Expression Blend 4 Photoshop CS5 Creative Suite 5.5 Expression Web 4 Expression Studio 4 Creative Suite® 5.5 Design
Creative Suite 5.5 Web Creative Suite 5.5 Production Startups Funding M&A Laptops Smart Phones
Desktops Cameras & Camcorders Netbooks Tablets Virtualization Microsoft Surface WordPress
Software Products Cloud Computing Current Affairs Technology TV TV
Earnings XAML E-Commerce MonoTouch Mono for Android Deals Electronics
Mobile Phone Laptop Tablet Book Computer Press Releases Reviews
Products Books Companies Windows Azure SQL Azure Interviews Mac
Web Browsers Symbian Windows Forms WPF Windows Services HTML 5 Office 365
SharePoint 2010 Exchange Server Adobe Visual Studio 2012 iPad Flex / Flash Games
Windows 9
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName