using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class 继承1 { //virtual虚函数,这样写便于子类重写 public virtual double Area(double a) { return a * 2; } } class Test : 继承1 { //重写父类的Area,当然也可以调用父类的Area方法 public override double Area(double b) { //关键字base.Area()调用了父类的Area方法 return base.Area(b) * 0.9; } } class Result { static void Main() { Test TT = new Test(); Console.WriteLine(TT.Area(10)); } } }
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Class4 { //申明2个构造函数 public Class4() { Console.WriteLine("Class4"); } int i; public Class4(int a) { i=a; Console.WriteLine("Class:{0}", i); } public void SS() { Console.WriteLine("BOSS"); } } class Test:Class4 { //调用父类(无参数的)构造函数 public Test() : base() { } //调用父类(有参数的)构造函数 public Test(int a) : base(a) { base.SS(); } } class TT { static void Main() { Test T = new Test(); Test T1 = new Test(10); } } }