C# 单重继承示例
以下 C# 示例展示了单重继承。在此示例中,基类为 Father,如下代码段声明:
class Father {
public void Display() {
Console.WriteLine("Display");
}
}我们的派生类为 Son,声明如下:
class Son : Father {
public void DisplayOne() {
Console.WriteLine("DisplayOne");
}
}示例
以下是 C# 单重继承的完整示例。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyAplication {
class Demo {
static void Main(string[] args) {
// Father class
Father f = new Father();
f.Display();
// Son class
Son s = new Son();
s.Display();
s.DisplayOne();
Console.ReadKey();
}
class Father {
public void Display() {
Console.WriteLine("Display");
}
}
class Son : Father {
public void DisplayOne() {
Console.WriteLine("DisplayOne");
}
}
}
}输出
Display Display DisplayOne
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP