Tip (V): Abstract Classes & Interfaces

Source: Internet
Author: User

Abstract class Abstraction:

Abstract classes and abstract methods can be identified with the abstract keyword. is a class or method that is not fully defined. Therefore, you cannot instantiate the operation directly.

Because he is not fully defined, it cannot be sealed with the sealed keyword.

Abstract methods do not include program bodies:

Public abstract class Student

{

Abstract method with no program body

public abstract void Getstudentid ();

Sub-class accessible fields

prodected int i;

Defining the properties of I

public int I

{

Get

{

return i;

}

}

}

Abstract methods for implementing abstract classes in inheriting classes

public class Ah:student

{

public AH (int a)

{

This.i=a;

}

public override void Getstudentid ()

{

Console.WriteLine (i.ToString ());

}

}

Interface interface:

A unified planning interface. Used to define a specification (such as the identification of a method) that needs to be adhered to in a subclass.

Abstract classes cannot be instantiated directly.

The identity of a method, property, or indexer can be defined in an interface.

All members in an interface have the default properties of public and abstract. The methods in the interface must be implemented in subclasses.

A class can ":" Inherit multiple interfaces, and an interface can inherit multiple interfaces.

public interface First

{

Indexer

String This[int i]

{

Get

Set

}

Method

int fun (int t);

Property

String J

{

Get

Set

}

}

Trivia (V): Abstract classes & Interfaces

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.