20141214 -- abstract base class, interface, 20141214 -- abstract interface

Source: Internet
Author: User

20141214 -- abstract base class, interface, 20141214 -- abstract interface

Abstract class:

Adding the keyword "abstract" before a class becomes an abstract class.

Abstract class, which cannot be used as an object. (Not New) It is generally used to reference subclass objects,

Abstract class Man {public void shuohua () {Console. WriteLine ("English ");}}

Abstract method:

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

public abstract void shuohua()

When a class inherits an abstract class, you must override the method. (Override keyword ),

Public override void shuohua () {Console. WriteLine ("English ");}

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

Abstract methods must be in abstract classes.Other methods can appear in the abstract class, but the abstract methods must be in the abstract class.

A common method in an abstract class can only be used in the current class.

An abstract class can only be used as a parent class.You cannot create an object.

Abstract attributes:

It can only be used in abstract classes.

Interface:

Interface keyword

Right-click 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 contain fields or methods.

An interface can be regarded as a pure abstract class. All its methods are abstract classes.It is mainly used to specify the method name,

Interface object. New must inherit the class of the interface:

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

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.