Sandy8606

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

先看例子:

Java中父类构造函数带有参数的情况下 子类构造函数的写法:

class Game {
Game(
int i) {
System.out.println(
"Game constructor");
}
}

class BoardGame extends Game {
BoardGame(
int i) {
super(i);
System.out.println(
"BoardGame constructor");
}
}

C#中父类构造函数带有参数的情况下 子类构造函数的写法:

class FatherClass
{
public FatherClass(int i)
{
Console.WriteLine(
"FatherClass is custrcted.");
}
}
class Program:FatherClass
{
public Program():base(1)
{
Console.WriteLine(
"ChildClass is custructed.");
}
}

感觉上 Java的写法要比C#感觉更直观。 为什么C#不支持直接在方法体内部写base(1)呢,有什么优点吗?希望高手能指点一下。

posted on 2011-02-12 11:18  Sandy8606  阅读(376)  评论(8编辑  收藏  举报