20141214--abstract base class, interface

Source: Internet
Author: User

Abstract class:

Adding the keyword "abstract" to the front of a class is an abstract class.

An abstract class that cannot be used as an object. (cannot new) is typically used to refer to a subclass object,

Abstract class Mans         {public  void Shuohua ()        {            Console.WriteLine (" English ");}    }

Abstract method:

Adding the keyword "abstract" before a method is an abstract method.

 Public Abstract void Shuohua ()

When you inherit an abstract class from a class, you must override the method. (override keyword),

 Public Override void Shuohua ()        {            Console.WriteLine (" English ");        }

All abstract methods in the parent class of the abstract class must all be implemented in the subclass.

the abstract method must be in an abstract class. Other methods can appear in an abstract class, but the abstract method must be in an abstract class.

An ordinary method in an abstract class that can only be used in the current class.

abstract classes can only be used as a parent class and cannot create objects.

Abstract Properties:

Can only be used in abstract classes.


Interface Keyword interface

Right--add--Add New Item--Select interface

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace jicheng{    interface  Interface1    {    }}

The interface cannot have fields, methods.

An interface can be seen as a pure abstract class, and all of its methods are abstract. mainly used to specify the method name,

Interface object that requires new to inherit the interface's class:

The name variable name of the interface type = New inherits the name of the class of this interface ();

20141214--abstract base class, interface

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.