保持快乐,善于表达,敢于创新
csharp 构造函数的有参和无参函数的区别.
上一篇 /
下一篇 2008-04-07 11:08:35
/ 个人分类:c#
构造函数中, 如果B类继承于A类时候, 那么B类先条用父类A的构造函数:
using System;
class A
{
public A()
{
Console.WriteLine("A without any parameter.");
}
public A(int i)
{
Console.WriteLine("A with a parameter.");
}
}
class B: A
{
public B()
{
Console.WriteLine("B without any parameters.");
}
public B (int i)
{
Console.WriteLine("B with a parameter");
}
}
class classcompare
{
public static void Main(){
B a =new B();
}
}
结果:
A without any parameter.
B without any parameters.
收藏
举报
TAG: