Abstract class and class member, abstract class member

Source: Internet
Author: User

Abstract class and class member, abstract class member

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

2. abstract classes are mainly used as base classes, but they can also inherit other common classes or abstract classes.

3. Abstract members can contain abstract members and ordinary implementation members.

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

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

6. Abstract members include methods, attributes, events, and indexes.

Namespace example act_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 declare public abstract int PropertyValue {get; set ;} public void Output () // abstract class can contain common implementation member {Console. writeLine ("I am Abstract Class A") ;}} public class MyClass: A {int MyValue; public override void DoWork (int I) // The derived class 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 ;}}}}}

 

Related Article

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.