【转】接口 与 抽象类
生活随笔
收集整理的這篇文章主要介紹了
【转】接口 与 抽象类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文轉自:http://blog.***/article.asp?id=89
介紹:
?? 在本文中,我將借一個DEMO討論下接口和抽象類。抽象類和接口的的概念對初學面向對象編程的人來說,總容易迷惑。所以,我試著討論下兩者的
理論并比較他們的使用。最后我將演示下怎么用C#使用它們。
背景:
一個抽象類在沒有執行時就象一個接口一樣。但在它們間有很多不同點,下面就解釋它們的概念,比較他們的相似點和不同點。
什么是抽象類?
一個抽象類是一種特殊的類,它無法實例化。所以,我們會問,那我們為什么還需要一個無法實例化的類呢?一個抽象類僅用來被繼承的,即它只
允許其他類繼承它,但自己不能實例化。對繼承的子集,抽象類的優勢是增強了某些層次結構。簡而言之,它是一種契約,使所有繼承它的子類都帶有
一樣的層次結構或標準。
什么是接口?
接口不是一個類。一個接口沒有執行機制。它只能有一個信號,換句話說,它只能夠定義方法名字,方法怎么實現的一無所有。有一點是和抽象類
相似的,它也具有一種契約,接口被用來定義所有子類的結構,或者說是定義一套子類方法。它們間的主要區別就是,一個類能實現或執行多個接口,
而只能從一個抽象類繼承。在C#中,不支持向C++那樣一個類可以多重繼承,但接口的運用,從另外的角度看,以用來實現了多繼承。
接口和抽象類:
?? 當我們創建一個接口,相當于我們基本上創建了一套沒有執行的方法,需要我們在子類中過載(Overriden)實現。這樣做有一個非常顯著的優勢,
它提供了一種方法,使一個類可以成為兩個類的一部分.
?? 當我們創建一個抽象類,相當于我們創建了一個基類,它擁有一個或著多個完整的方法,??
?? 但至少有一個方法沒有實現,即被聲明為抽象方法。若所有的方法都沒實現,那它和接口的功能是一樣的,只是它還遵守無法被繼承的規則。
?? 抽象類的目的是提供了一個基本類,定義了子類將如何設計,允許程序員在子類中實現這些方法。
特點
接 口
????????抽象類
多繼承
一個類能從幾個接口繼承
一個類只能繼承于一個抽象類????????????
實現方式
一個接口沒有任何實現的代碼只顯示方法名
抽象類可以提供完整的方法實現的代碼
核心與外圍
接口用來定義類的外圍功能.
比如人類和交通工具兩個類都能從IMOVABLE接口繼承。??
抽象類多用來定義一個類的核心層
使用場合
如果很多實現都共享一些方法,則??????
用接口比較
如果很多實現使用同一系列方法,使用一樣的屬性,則用抽象類較好
速度??
要求更多的時間,去找到實際的子類實現的方法
比較快
功能擴展性
如果我們要給接口添加一個方法,我們要捕捉所有使用該接口的實現子類,并分別添加一個新的方法,并實現它.
如果我們要給抽象類添加一個新的方法我們可以在抽象實現,也可以在子類實現
代碼實例:
用代碼來實現會更簡單些。這里有一個Employee抽象類,和一個IEmployee接口。我會用實現的對象分別繼承于Employee和IEmployee,Emp_Fulltime繼承于Employee,Emp_Fulltime2繼承于IEmployee。
在測試中,我創建兩者的實例,并設置他們的屬性,調用一個calculateWage的方法。
Abstract Class Employee
1 using System;
2
3 namespace AbstractsANDInterfaces
4 {
5???? ///
6
7???? /// Summary description for Employee.
8
9???? ///
10
11????
12???? public abstract class Employee
13???? {
14???????? //we can have fields and properties
15
16???????? //in the Abstract class
17
18???????? protected String id;
19???????? protected String lname;
20???????? protected String fname;
21
22???????? //properties
23
24???????? public abstract String ID
25???????? {
26???????????? get;
27???????????? set;
28???????? }
29
30???????? public abstract String FirstName
31???????? {
32???????????? get;
33???????????? set;
34???????? }
35????????
36???????? public abstract String LastName
37???????? {
38???????????? get;
39???????????? set;
40???????? }
41???????? //completed methods
42
43???????? public String Update()
44???????? {
45???????????? return "Employee " + id + " " +
46?????????????????????? lname + " " + fname +
47?????????????????????? " updated";
48???????? }
49???????? //completed methods
50
51???????? public String Add()
52???????? {
53???????????? return "Employee " + id + " " +
54?????????????????????? lname + " " + fname +
55?????????????????????? " added";
56???????? }
57???????? //completed methods
58
59???????? public String Delete()
60???????? {
61???????????? return "Employee " + id + " " +
62?????????????????????? lname + " " + fname +
63?????????????????????? " deleted";
64???????? }
65???????? //completed methods
66
67???????? public String Search()
68???????? {
69???????????? return "Employee " + id + " " +
70?????????????????????? lname + " " + fname +
71?????????????????????? " found";
72???????? }
73
74???????? //abstract method that is different
75
76???????? //from Fulltime and Contractor
77
78???????? //therefore i keep it uncompleted and
79
80???????? //let each implementation
81
82???????? //complete it the way they calculate the wage.
83
84???????? public abstract String CalculateWage();
85????????
86???? }
87 }
88
Interface Employee??1 using System;
2
3
4 namespace AbstractsANDInterfaces
5 {
6???? /// <summary>
7
8???? /// Summary description for IEmployee.
9
10???? /// </summary>
11
12???? public interface IEmployee
13???? {
14???????? //cannot have fields. uncommenting
15
16???????? //will raise error!
17
18 //????????protected String id;
19
20 //????????protected String lname;
21
22 //????????protected String fname;
23
24
25???????? //just signature of the properties
26
27???????? //and methods.
28
29???????? //setting a rule or contract to be
30
31???????? //followed by implementations.
32
33???????? String ID
34???????? {
35???????????? get;
36???????????? set;
37???????? }
38
39???????? String FirstName
40???????? {
41???????????? get;
42???????????? set;
43???????? }
44????????
45???????? String LastName
46???????? {
47???????????? get;
48???????????? set;
49???????? }
50????????
51???????? // cannot have implementation
52
53???????? // cannot have modifiers public
54
55???????? // etc all are assumed public
56
57???????? // cannot have virtual
58
59
60???????? String Update();
61
62???????? String Add();
63
64???????? String Delete();
65
66???????? String Search();
67
68???????? String CalculateWage();
69???? }
70 }
71
Inherited Objects
Emp_Fulltime:
??1 using System;
??2
??3 namespace AbstractsANDInterfaces
??4 {
??5???? ///
??6
??7???? /// Summary description for Emp_Fulltime.
??8
??9???? ///
10
11??????
12???? //Inheriting from the Abstract class
13
14???? public class Emp_Fulltime : Employee
15???? {
16???????? //uses all the properties of the
17
18???????? //Abstract class therefore no
19
20???????? //properties or fields here!
21
22
23???????? public Emp_Fulltime()
24???????? {
25???????? }
26
27
28???????? public override String ID
29???????? {
30???????????? get
31???????????? {
32???????????????? return id;
33???????????? }
34???????????? set
35???????????? {
36???????????????? id = value;
37???????????? }
38???????? }
39????????
40???????? public override String FirstName
41???????? {
42???????????? get
43???????????? {
44???????????????? return fname;
45???????????? }
46???????????? set
47???????????? {
48???????????????? fname = value;
49???????????? }
50???????? }
51
52???????? public override String LastName
53???????? {
54???????????? get
55???????????? {
56???????????????? return lname;
57???????????? }
58???????????? set
59???????????? {
60???????????????? lname = value;
61???????????? }
62???????? }
63
64???????? //common methods that are
65
66???????? //implemented in the abstract class
67
68???????? public new String Add()
69???????? {
70???????????? return base.Add();
71???????? }
72???????? //common methods that are implemented
73
74???????? //in the abstract class
75
76???????? public new String Delete()
77???????? {
78???????????? return base.Delete();
79???????? }
80???????? //common methods that are implemented
81
82???????? //in the abstract class
83
84???????? public new String Search()
85???????? {
86???????????? return base.Search();
87???????? }
88???????? //common methods that are implemented
89
90???????? //in the abstract class
91
92???????? public new String Update()
93???????? {
94???????????? return base.Update();
95???????? }
96????????
97???????? //abstract method that is different
98
99???????? //from Fulltime and Contractor
100
101???????? //therefore I override it here.
102
103???????? public override String CalculateWage()
104???????? {
105???????????? return "Full time employee " +
106?????????????????? base.fname + " is calculated " +
107?????????????????? "using the Abstract class";
108???????? }
109???? }
110 }
111
Emp_Fulltime2
??1 using System;
??2
??3 namespace AbstractsANDInterfaces
??4 {
??5???? ///
??6
??7???? /// Summary description for Emp_fulltime2.
??8
??9???? ///
10
11????
12???? //Implementing the interface
13
14???? public class Emp_fulltime2 : IEmployee
15???? {
16???????? //All the properties and
17
18???????? //fields are defined here!
19
20???????? protected String id;
21???????? protected String lname;
22???????? protected String fname;
23
24???????? public Emp_fulltime2()
25???????? {
26???????????? //
27
28???????????? // TODO: Add constructor logic here
29
30???????????? //
31
32???????? }
33
34???????? public String ID
35???????? {
36???????????? get
37???????????? {
38???????????????? return id;
39???????????? }
40???????????? set
41???????????? {
42???????????????? id = value;
43???????????? }
44???????? }
45????????
46???????? public String FirstName
47???????? {
48???????????? get
49???????????? {
50???????????????? return fname;
51???????????? }
52???????????? set
53???????????? {
54???????????????? fname = value;
55???????????? }
56???????? }
57
58???????? public String LastName
59???????? {
60???????????? get
61???????????? {
62???????????????? return lname;
63???????????? }
64???????????? set
65???????????? {
66???????????????? lname = value;
67???????????? }
68???????? }
69
70???????? //all the manipulations including Add,Delete,
71
72???????? //Search, Update, Calculate are done
73
74???????? //within the object as there are not
75
76???????? //implementation in the Interface entity.
77
78???????? public String Add()
79???????? {
80???????????? return "Fulltime Employee " +
81?????????????????????????? fname + " added.";
82???????? }
83
84???????? public String Delete()
85???????? {
86???????????? return "Fulltime Employee " +
87???????????????????????? fname + " deleted.";
88???????? }
89
90???????? public String Search()
91???????? {
92???????????? return "Fulltime Employee " +
93????????????????????????fname + " searched.";
94???????? }
95
96???????? public String Update()
97???????? {
98???????????? return "Fulltime Employee " +
99???????????????????????? fname + " updated.";
100???????? }
101????????
102???????? //if you change to Calculatewage().
103
104???????? //Just small 'w' it will raise
105
106???????? //error as in interface
107
108???????? //it is CalculateWage() with capital 'W'.
109
110???????? public String CalculateWage()
111???????? {
112???????????? return "Full time employee " +
113?????????????????? fname + " caluculated using " +
114?????????????????? "Interface.";
115???????? }
116???? }
117 }
118
Code for testing
1 private void InterfaceExample_Click(object sender,
2???????????????????????????????? System.EventArgs e)
3 {
4???? try
5???? {
6
7???????? IEmployee emp;
8
9???????? Emp_fulltime2 emp1 = new Emp_fulltime2();
10???????? //has to be casted because of the interface!
11
12???????? emp = (IEmployee) emp1;
13???????? emp.ID = "2234";
14???????? emp.FirstName= "Rahman" ;
15???????? emp.LastName = "Mahmoodi" ;
16???????? //call add method od the object
17
18???????? MessageBox.Show(emp.Add().ToString());
19????????
20???????? //call the CalculateWage method
21
22???????? MessageBox.Show(emp.CalculateWage().ToString());
23
24
25???? }
26???? catch(Exception ex)
27???? {
28???????? MessageBox.Show(ex.Message);
29???? }
30
31 }
32
33 private void cmdAbstractExample_Click(object sender,
34????????????????????????????????????System.EventArgs e)
35 {
36
37???? Employee emp;
38???? //no casting is requird!
39
40???? emp = new Emp_Fulltime();
41????
42
43???? emp.ID = "2244";
44???? emp.FirstName= "Maria" ;
45???? emp.LastName = "Robinlius" ;
46???? MessageBox.Show(emp.Add().ToString());
47
48???? //call the CalculateWage method
49
50???? MessageBox.Show(emp.CalculateWage().ToString());
51
52 }
53
結論:
我已經解釋了接口和抽象類的不同點,并用一個Demo Project 講解了他們實現的不同點.
介紹:
?? 在本文中,我將借一個DEMO討論下接口和抽象類。抽象類和接口的的概念對初學面向對象編程的人來說,總容易迷惑。所以,我試著討論下兩者的
理論并比較他們的使用。最后我將演示下怎么用C#使用它們。
背景:
一個抽象類在沒有執行時就象一個接口一樣。但在它們間有很多不同點,下面就解釋它們的概念,比較他們的相似點和不同點。
什么是抽象類?
一個抽象類是一種特殊的類,它無法實例化。所以,我們會問,那我們為什么還需要一個無法實例化的類呢?一個抽象類僅用來被繼承的,即它只
允許其他類繼承它,但自己不能實例化。對繼承的子集,抽象類的優勢是增強了某些層次結構。簡而言之,它是一種契約,使所有繼承它的子類都帶有
一樣的層次結構或標準。
什么是接口?
接口不是一個類。一個接口沒有執行機制。它只能有一個信號,換句話說,它只能夠定義方法名字,方法怎么實現的一無所有。有一點是和抽象類
相似的,它也具有一種契約,接口被用來定義所有子類的結構,或者說是定義一套子類方法。它們間的主要區別就是,一個類能實現或執行多個接口,
而只能從一個抽象類繼承。在C#中,不支持向C++那樣一個類可以多重繼承,但接口的運用,從另外的角度看,以用來實現了多繼承。
接口和抽象類:
?? 當我們創建一個接口,相當于我們基本上創建了一套沒有執行的方法,需要我們在子類中過載(Overriden)實現。這樣做有一個非常顯著的優勢,
它提供了一種方法,使一個類可以成為兩個類的一部分.
?? 當我們創建一個抽象類,相當于我們創建了一個基類,它擁有一個或著多個完整的方法,??
?? 但至少有一個方法沒有實現,即被聲明為抽象方法。若所有的方法都沒實現,那它和接口的功能是一樣的,只是它還遵守無法被繼承的規則。
?? 抽象類的目的是提供了一個基本類,定義了子類將如何設計,允許程序員在子類中實現這些方法。
特點
接 口
????????抽象類
多繼承
一個類能從幾個接口繼承
一個類只能繼承于一個抽象類????????????
實現方式
一個接口沒有任何實現的代碼只顯示方法名
抽象類可以提供完整的方法實現的代碼
核心與外圍
接口用來定義類的外圍功能.
比如人類和交通工具兩個類都能從IMOVABLE接口繼承。??
抽象類多用來定義一個類的核心層
使用場合
如果很多實現都共享一些方法,則??????
用接口比較
如果很多實現使用同一系列方法,使用一樣的屬性,則用抽象類較好
速度??
要求更多的時間,去找到實際的子類實現的方法
比較快
功能擴展性
如果我們要給接口添加一個方法,我們要捕捉所有使用該接口的實現子類,并分別添加一個新的方法,并實現它.
如果我們要給抽象類添加一個新的方法我們可以在抽象實現,也可以在子類實現
代碼實例:
用代碼來實現會更簡單些。這里有一個Employee抽象類,和一個IEmployee接口。我會用實現的對象分別繼承于Employee和IEmployee,Emp_Fulltime繼承于Employee,Emp_Fulltime2繼承于IEmployee。
在測試中,我創建兩者的實例,并設置他們的屬性,調用一個calculateWage的方法。
Abstract Class Employee
1 using System;
2
3 namespace AbstractsANDInterfaces
4 {
5???? ///
6
7???? /// Summary description for Employee.
8
9???? ///
10
11????
12???? public abstract class Employee
13???? {
14???????? //we can have fields and properties
15
16???????? //in the Abstract class
17
18???????? protected String id;
19???????? protected String lname;
20???????? protected String fname;
21
22???????? //properties
23
24???????? public abstract String ID
25???????? {
26???????????? get;
27???????????? set;
28???????? }
29
30???????? public abstract String FirstName
31???????? {
32???????????? get;
33???????????? set;
34???????? }
35????????
36???????? public abstract String LastName
37???????? {
38???????????? get;
39???????????? set;
40???????? }
41???????? //completed methods
42
43???????? public String Update()
44???????? {
45???????????? return "Employee " + id + " " +
46?????????????????????? lname + " " + fname +
47?????????????????????? " updated";
48???????? }
49???????? //completed methods
50
51???????? public String Add()
52???????? {
53???????????? return "Employee " + id + " " +
54?????????????????????? lname + " " + fname +
55?????????????????????? " added";
56???????? }
57???????? //completed methods
58
59???????? public String Delete()
60???????? {
61???????????? return "Employee " + id + " " +
62?????????????????????? lname + " " + fname +
63?????????????????????? " deleted";
64???????? }
65???????? //completed methods
66
67???????? public String Search()
68???????? {
69???????????? return "Employee " + id + " " +
70?????????????????????? lname + " " + fname +
71?????????????????????? " found";
72???????? }
73
74???????? //abstract method that is different
75
76???????? //from Fulltime and Contractor
77
78???????? //therefore i keep it uncompleted and
79
80???????? //let each implementation
81
82???????? //complete it the way they calculate the wage.
83
84???????? public abstract String CalculateWage();
85????????
86???? }
87 }
88
Interface Employee??1 using System;
2
3
4 namespace AbstractsANDInterfaces
5 {
6???? /// <summary>
7
8???? /// Summary description for IEmployee.
9
10???? /// </summary>
11
12???? public interface IEmployee
13???? {
14???????? //cannot have fields. uncommenting
15
16???????? //will raise error!
17
18 //????????protected String id;
19
20 //????????protected String lname;
21
22 //????????protected String fname;
23
24
25???????? //just signature of the properties
26
27???????? //and methods.
28
29???????? //setting a rule or contract to be
30
31???????? //followed by implementations.
32
33???????? String ID
34???????? {
35???????????? get;
36???????????? set;
37???????? }
38
39???????? String FirstName
40???????? {
41???????????? get;
42???????????? set;
43???????? }
44????????
45???????? String LastName
46???????? {
47???????????? get;
48???????????? set;
49???????? }
50????????
51???????? // cannot have implementation
52
53???????? // cannot have modifiers public
54
55???????? // etc all are assumed public
56
57???????? // cannot have virtual
58
59
60???????? String Update();
61
62???????? String Add();
63
64???????? String Delete();
65
66???????? String Search();
67
68???????? String CalculateWage();
69???? }
70 }
71
Inherited Objects
Emp_Fulltime:
??1 using System;
??2
??3 namespace AbstractsANDInterfaces
??4 {
??5???? ///
??6
??7???? /// Summary description for Emp_Fulltime.
??8
??9???? ///
10
11??????
12???? //Inheriting from the Abstract class
13
14???? public class Emp_Fulltime : Employee
15???? {
16???????? //uses all the properties of the
17
18???????? //Abstract class therefore no
19
20???????? //properties or fields here!
21
22
23???????? public Emp_Fulltime()
24???????? {
25???????? }
26
27
28???????? public override String ID
29???????? {
30???????????? get
31???????????? {
32???????????????? return id;
33???????????? }
34???????????? set
35???????????? {
36???????????????? id = value;
37???????????? }
38???????? }
39????????
40???????? public override String FirstName
41???????? {
42???????????? get
43???????????? {
44???????????????? return fname;
45???????????? }
46???????????? set
47???????????? {
48???????????????? fname = value;
49???????????? }
50???????? }
51
52???????? public override String LastName
53???????? {
54???????????? get
55???????????? {
56???????????????? return lname;
57???????????? }
58???????????? set
59???????????? {
60???????????????? lname = value;
61???????????? }
62???????? }
63
64???????? //common methods that are
65
66???????? //implemented in the abstract class
67
68???????? public new String Add()
69???????? {
70???????????? return base.Add();
71???????? }
72???????? //common methods that are implemented
73
74???????? //in the abstract class
75
76???????? public new String Delete()
77???????? {
78???????????? return base.Delete();
79???????? }
80???????? //common methods that are implemented
81
82???????? //in the abstract class
83
84???????? public new String Search()
85???????? {
86???????????? return base.Search();
87???????? }
88???????? //common methods that are implemented
89
90???????? //in the abstract class
91
92???????? public new String Update()
93???????? {
94???????????? return base.Update();
95???????? }
96????????
97???????? //abstract method that is different
98
99???????? //from Fulltime and Contractor
100
101???????? //therefore I override it here.
102
103???????? public override String CalculateWage()
104???????? {
105???????????? return "Full time employee " +
106?????????????????? base.fname + " is calculated " +
107?????????????????? "using the Abstract class";
108???????? }
109???? }
110 }
111
Emp_Fulltime2
??1 using System;
??2
??3 namespace AbstractsANDInterfaces
??4 {
??5???? ///
??6
??7???? /// Summary description for Emp_fulltime2.
??8
??9???? ///
10
11????
12???? //Implementing the interface
13
14???? public class Emp_fulltime2 : IEmployee
15???? {
16???????? //All the properties and
17
18???????? //fields are defined here!
19
20???????? protected String id;
21???????? protected String lname;
22???????? protected String fname;
23
24???????? public Emp_fulltime2()
25???????? {
26???????????? //
27
28???????????? // TODO: Add constructor logic here
29
30???????????? //
31
32???????? }
33
34???????? public String ID
35???????? {
36???????????? get
37???????????? {
38???????????????? return id;
39???????????? }
40???????????? set
41???????????? {
42???????????????? id = value;
43???????????? }
44???????? }
45????????
46???????? public String FirstName
47???????? {
48???????????? get
49???????????? {
50???????????????? return fname;
51???????????? }
52???????????? set
53???????????? {
54???????????????? fname = value;
55???????????? }
56???????? }
57
58???????? public String LastName
59???????? {
60???????????? get
61???????????? {
62???????????????? return lname;
63???????????? }
64???????????? set
65???????????? {
66???????????????? lname = value;
67???????????? }
68???????? }
69
70???????? //all the manipulations including Add,Delete,
71
72???????? //Search, Update, Calculate are done
73
74???????? //within the object as there are not
75
76???????? //implementation in the Interface entity.
77
78???????? public String Add()
79???????? {
80???????????? return "Fulltime Employee " +
81?????????????????????????? fname + " added.";
82???????? }
83
84???????? public String Delete()
85???????? {
86???????????? return "Fulltime Employee " +
87???????????????????????? fname + " deleted.";
88???????? }
89
90???????? public String Search()
91???????? {
92???????????? return "Fulltime Employee " +
93????????????????????????fname + " searched.";
94???????? }
95
96???????? public String Update()
97???????? {
98???????????? return "Fulltime Employee " +
99???????????????????????? fname + " updated.";
100???????? }
101????????
102???????? //if you change to Calculatewage().
103
104???????? //Just small 'w' it will raise
105
106???????? //error as in interface
107
108???????? //it is CalculateWage() with capital 'W'.
109
110???????? public String CalculateWage()
111???????? {
112???????????? return "Full time employee " +
113?????????????????? fname + " caluculated using " +
114?????????????????? "Interface.";
115???????? }
116???? }
117 }
118
Code for testing
1 private void InterfaceExample_Click(object sender,
2???????????????????????????????? System.EventArgs e)
3 {
4???? try
5???? {
6
7???????? IEmployee emp;
8
9???????? Emp_fulltime2 emp1 = new Emp_fulltime2();
10???????? //has to be casted because of the interface!
11
12???????? emp = (IEmployee) emp1;
13???????? emp.ID = "2234";
14???????? emp.FirstName= "Rahman" ;
15???????? emp.LastName = "Mahmoodi" ;
16???????? //call add method od the object
17
18???????? MessageBox.Show(emp.Add().ToString());
19????????
20???????? //call the CalculateWage method
21
22???????? MessageBox.Show(emp.CalculateWage().ToString());
23
24
25???? }
26???? catch(Exception ex)
27???? {
28???????? MessageBox.Show(ex.Message);
29???? }
30
31 }
32
33 private void cmdAbstractExample_Click(object sender,
34????????????????????????????????????System.EventArgs e)
35 {
36
37???? Employee emp;
38???? //no casting is requird!
39
40???? emp = new Emp_Fulltime();
41????
42
43???? emp.ID = "2244";
44???? emp.FirstName= "Maria" ;
45???? emp.LastName = "Robinlius" ;
46???? MessageBox.Show(emp.Add().ToString());
47
48???? //call the CalculateWage method
49
50???? MessageBox.Show(emp.CalculateWage().ToString());
51
52 }
53
結論:
我已經解釋了接口和抽象類的不同點,并用一個Demo Project 講解了他們實現的不同點.
轉載于:https://www.cnblogs.com/feima-lxl/archive/2008/04/25/1170971.html
總結
以上是生活随笔為你收集整理的【转】接口 与 抽象类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bzoj 1024 [ SCOI 200
- 下一篇: PPT常用功能及其实现