构造函数是否可被重写?
2013-04-20 19:02
211 查看
构造函数不能被继承,因此不能重写,但可以被重载。
View Code
View Code
public class Counter { // 构造函数可以被重载。 public Counter() { } public Counter(string s) { } public virtual void Test() { } public static int currentCount; public static int IncrementCount() { return ++currentCount; } } public class Counter1 : Counter { public override void Test() { } } class TestCounter { static void Main() { // If you uncomment the following statement, it will generate // an error because the constructor is inaccessible: // Counter aCounter = new Counter(); // Error Counter.currentCount = 100; Counter.IncrementCount(); System.Console.WriteLine("New count: {0}", Counter.currentCount); } }
相关文章推荐
- 重写函数的Equals方法,来确定需要比较类是否相同的条件
- C++ 构造函数和析构函数是否可以继承?
- java集合框架(hashSet自定义元素是否相同,重写hashCode和equals方法)
- java中子类继承父类时是否继承构造函数呢?
- C++构造函数和析构函数是否可以为virtual?
- java中子类继承父类时,是否继承构造函数
- vector push_back 是否调用构造函数
- 构造函数、析构函数是否要声明为虚函数的问题(网络转载)
- 【代码重构 & JDT】判断一个方法是否是实现重写,继承重写和递归
- C#中的重载,重写,构造函数
- c#关于几个构造函数 静态构造函数 重写 非重写的实例化 测试试题
- 判断对象是否相等---重写equals方法
- C++ 构造函数和析构函数是否可以继承?
- JAVA中子类是否可以可以继承、重写父类的静态方法--总结
- 是否应该扔掉就代码,重写整个软件?
- 构造函数和析构函数是否可以被重载
- window.location的重写及判断location是否被重写
- 定义平面中的一个Circle类, 1编写一个无参数构造函数, 2编写一个有参的构造函数 3在主函数中调用无参构造函数生成圆的实例c1,调用有参构造函数生成圆的实例c2,调用实例方法判断c1和c2是否重
- 构造函数是否有new的区别
- A::fun();这样调用后, A类的构造函数和析构函数是否会被调用?------不会!