Abstract classes and class members

Source: Internet
Author: User

1. You cannot create an instance of an abstract class.

2. Abstract classes are primarily used as base classes, but abstract classes can also inherit other ordinary classes or abstract classes.

3. Abstract members can contain abstract members and ordinary band-implemented members.

4. Any class derived from an abstract class must use the override keyword to implement all of the abstract members of the class, unless the derived class itself is an abstract class.

5. Abstract members can only be declared in abstract classes.

6. Abstract members include: Methods, properties, events, indexes.

Namespace Abstract_example

{
Class Program
{
static void Main (string[] args)
{
MyClass m = new MyClass ();
M.propertyvalue = 100;
M.output ();
M.dowork (M.propertyvalue);
Console.readkey ();
}
Public abstract class A
{
public abstract void DoWork (int i);// Abstract members can only be declared in abstract classes
public abstract int PropertyValue
{
Get
Set
}
public void Output ()//an abstract class can contain members of an ordinary band implementation
{
Console.WriteLine ("I am Abstract Class A");
}
}
public class Myclass:a
{
int myvalue;
public override void DoWork (int i)//derived classes must all implement all abstract members in the base class
{
Console.WriteLine ("I am Class MyClass. My Value is {0} ", i);
}
public override int PropertyValue

{
get {return myvalue;}
Set{myvalue = value;}
}
}
}
}

Abstract classes and class members

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.