An abstract class member is a member that is specified in a class but not implemented. Classes that inherit from the class will have to implement the abstract member. Abstract members are a technique for ensuring a common interface with descendant classes. An abstract class is a class you cannot instantiate. A pure abstract class is a class with only abstract members.
Languages Focus Abstraction is supported at various levels with each language. A language could enforce abstraction at the class level (either enforcing a no-instantiation rule or a only abstract members rule), and with class members (member methods and/or properties).
VB.Net:
MustInherit, MustOverride, Overrides
VB.Net supports abstract class members and abstract classes using the MustInherit and MustOverride modifiers.
An abstract class is indicated with a MustInherit modifier and is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties.
An abstract member is either a method (implicitly virtual), property , indexer , or event in an abstract class. You can add abstract members ONLY to abstract classes using the MustOverride keyword. Then you override it in a descendant class with Overrides .
Syntax Example: Public MustInherit Class Cyborg Public MustOverride Sub Speak(ByVal pMessage As String) End Class Public Class Series600 Inherits Cyborg Public Overrides Sub Speak(ByVal pMessage As String) MessageBox.Show(pMessage) End Sub End Class
Cross Reference Examples:
ASP Classic:
Not Supported
C#:
abstract, override
C# supports abstract class members and abstract classes using the abstract modifier.
An abstract class is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties.
An abstract member is either a method (implicitly virtual), property , indexer , or event in an abstract class. You can add abstract members ONLY to abstract classes using the abstract keyword. Then you override it in a descendant class with Override .
Syntax Example: abstract public class Cyborg : System.Object{ abstract public void Speak(string pMessage); } public class Series600 : Cyborg { public override void Speak(string pMessage) { MessageBox.Show(pMessage); } }
C++:
=0 in a virtual method
AbstractMemberFunction is a pure virtual function makes this class Abstract class indicated by the "=0"and NonAbstractMemberFunction1 is a virtual function.
Syntax Example: class AbstractClass { public: virtual void AbstractMemberFunction() = 0; virtual void NonAbstractMemberFunction1(); };
Corel Paradox:
Not Supported
Delphi:
abstract, override
Delphi for Win32 supports abstract class members using the abstract keyword. You can even instantiate instances of a class that contains abstract members. Then you override each abstract member in a descendant class with Override .
Delphi does not support setting an entire class as abstract. You can create an abstract class (a class with one or more abstract methods), but there is no way to tell the compiler to not allow the instantiation of the abstract class.
Delphi does not support abstract member properties directly. To implement an abstract properity, make use of abstract methods. That is, you can read a GetPropertyX abstract function and write to a SetPropertyX abstract procedure. In effect, creating an abstract property.
Syntax Example: TCyborg = class(TObject) public procedure Speak(pMessage: String); virtual; abstract; procedure Walk; virtual; abstract; end; TSeries600 = class(TCyborg) public procedure Speak(pMessage: String); override; procedure Walk; override; end;
Delphi Prism:
abstract, override
Prism supports abstract class members and abstract classes using the abstract keyword.
An abstract class is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties.
An abstract member is either a method (method, procedure, or function), a property, or an event in an abstract class. You can add abstract members ONLY to abstract classes using the abstract keyword.
Alternatively, you can use the empty keyword in place of abstract if you wish to instantiate the abstract class. Then you override it in a descendant class with Override .
Syntax Example: Cyborg = public abstract class(System.Object) public //You can put "virtual; abstract;" //but it's implied with just "abstract;" method Speak(pMessage: String); abstract; method Walk; virtual; abstract; end; Series600 = public class(Cyborg) public procedure Speak(pMessage: String); override; procedure Walk; override; end;
Java:
abstract
Java supports marking a full class as abstract as well as class members. A subclass must either implement the abstract members or you must declare the subclass abstract (which delays the implementation to it's subclass).
Syntax Example: public abstract class Dog { abstract void Bark(); }