构造函数
默认的构造函数
如果我们不写 系统会自动给我们创建
构造函数是没有返回值
构造函数可以有多个(重载)
ta和结构体不一样 ta 可以随意去赋值指定的元素
当我们自己编写了构造函数之后系统不会为我们再创建一个默认的构造函数
一般我们有多个构造函数的时候 都会去编写一个默认的构造函数
析构函数
作用 在对象生命周期结束的时候被调用
1.在结构体不能存在析构函数
2.析构函数不能重载 不能被调用 ta是自动调的
3.一个类只能有一个析构函数
4.没有修饰符也没有参数
继承class A:B
A继承自B 你们A有用B类中所有公开字段属性方法
继承是不可逆的。子类继承父类的方法 而父类不能继承子类的方法
子类在继承父类 在实例化对象的时候 会先去调用父类的构造方法 再调用自己的构造方法
继承具有传递性A:B:C A也能继承B中的内容
class Sect
{
public string Martialarts_name;
public string Martialarts_Power;
public void Attack()
{
Console.WriteLine(“飞剑攻击”);
}
}
class Gumu : Sect
{
public new void Attack()
{
Console.WriteLine("乌鸦坐飞机");
}
}
class Quanzhen : Sect
{
public new void Attack()
{
Console.WriteLine("奔雷剑法");
}
}
class Huashan : Sect
{
public new void Attack()
{
Console.WriteLine("万剑归一");
}
}