The foundation is the top priority-Abstract programming (abstract class polymorphism)

Source: Internet
Author: User

Back to directory

PreviousArticleIt mainly shows you the Conversion Relationship between the base class and the derived class, that is, they cannot be converted to each other and can only be converted from the derived class to the base class, next we will look at an abstract class and a programming method implemented by its derived class, that is, abstract-oriented programming.

The following is an example of abstract-Oriented Programming: (complete)Code)

 1       ///   <Summary> 
2 /// Base Class
3 /// </Summary>
4 Abstract Class Parent
5 {
6 Public String Name { Get ; Set ;}
7 }
8 /// <Summary>
9 /// Derived Class 1
10 /// </Summary>
11 Class Sub1: parent {}
12 /// <Summary>
13 /// Derived Class 2
14 /// </Summary>
15 Class Sub2: parent {}
16 Class Program
17 {
18 Static Void Main ( String [] ARGs)
19 {
20
21 Sub1 S1 = New Sub1 {name = " Sub1 class " ,};
22 Test (S1 );
23 Console. readkey ();
24 }
25 /// <Summary>
26 /// Abstract programming (class polymorphism)
27 /// </Summary>
28 /// <Param name = "entity"> </param>
29 Static Void Test (parent entity)
30 {
31 Console. writeline (entity. GetType ());
32 }
33 }

Back to directory

 

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.