新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
實(shí)現(xiàn)C#繼承與C#多態(tài)的實(shí)例演示
在C#中實(shí)現(xiàn)OOP思想,絲毫不遜色于Java,下面我通知兩句話來幫助初學(xué)者理解C#繼承與C#多態(tài)

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),上高企業(yè)網(wǎng)站建設(shè),上高品牌網(wǎng)站建設(shè),網(wǎng)站定制,上高網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,上高網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
C#繼承:子類使用父類的方法。
C#多態(tài):父類使用子類的方法。
下面通過一個(gè)簡單的程序來說明C#繼承與C#多態(tài):
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Graph
- {
- class Program
- {
- static void Main(string[] args)
- {
- circular c = new circular();
- Console.WriteLine(c.getSides());
- square s = new square();
- Console.WriteLine(s.getSides());
- //這就是多態(tài)
- Graph g;
- g= new circular();
- g.getSides(); //父類使用子類的方法
- g = new square();
- g.getSides(); //父類使用子類的方法
- }
- }
- public abstract class Graph
- {
- public abstract int getSides();
- }
- //這就是繼承
- public class circular : Graph
- {
- public override int getSides() //子類使用父類的方法
- {
- return 1;
- }
- }
- public class square : Graph
- {
- public override int getSides() //子類使用父類的方法
- {
- return 2;
- }
- }
- }
網(wǎng)站欄目:實(shí)現(xiàn)C#繼承與C#多態(tài)的實(shí)例演示
地址分享:http://www.5511xx.com/article/cdepcho.html


咨詢
建站咨詢
