Created
March 17, 2015 00:42
-
-
Save dnasca/526832bf605b19d504bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
/* //Abstract Classes// | |
* | |
* An abstract class is incomplete and CANNOT be instantiated | |
* | |
* An abstract class CAN ONLY be used as a base class | |
* | |
* An abstract class CANNOT be sealed | |
* | |
* An abstract class may contain abstract members (methods, properties, indexers, events, etc) but is not mandatory | |
* | |
* A non-abstract class derived from an abstract class MUST provide implementations for all inherited abstract members | |
* | |
* !@!@ If a class inherits an abstract class, there are 2 options available for that class !@!@ | |
* Option 1: Provide implementation for all the abstract members inherited from the base abstract class | |
* Option 2: If the class does not wish to provide implementations for all the abstract members that are | |
* inherited from the abstract class, then the class has to marked as abstract | |
* | |
*/ | |
public abstract class AbstractClass //cannot be instantiated, can only be used as a base class | |
{ | |
public abstract void Print(); | |
//if method is marked as abstract, you CANNOT have an implementation here, but must provide | |
//the implementation in any inherited classes | |
} | |
public abstract class AnotherAbstractClass : AbstractClass | |
//if you do not wish to provide the implementation of the inherited abstract class method | |
//then you MUST mark the class that is INHERITING, as abstract | |
{ | |
//this class is inhereting from 'AbstractClass', which provides an abstract method, but it does not need to be implemented here | |
//because this class is also marked as abstract | |
} | |
public class Program : AbstractClass | |
{ | |
public override void Print() //implementation of 'AbstractClass' Print method | |
{ | |
Console.WriteLine("AbstractClass Print method called"); | |
} | |
public static void Main() | |
{ | |
Program P = new Program(); | |
P.Print(); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment