扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:sincere1314 来源:论坛 2007年11月13日
关键字:
using System; class Point { public double x, y; public Point() { this.x = 0; this.y = 0; } public Point(double x, double y) { this.x = x; this.y = y; } … } class Test { static void Main() { Point a = new Point(); Point b = new Point(3, 4); // 用构造函数初始化对象 … } } |
using System.Data; class Employee { private static DataSet ds; static Employee() { ds = new DataSet(...); } ... } |
class A { private int x; public A( ) { x = 0; } public A( int i ) { x = i; } }; class B : A { private int y; public B( ) { y = 0; } public B( int i ) { y = i; } public B( int i, int j ):A(i) { y = j; } }; B b1 = new B(); //执行基类A的构造函数A(),再执行派生类的构造函数B() B b2 = new B(1); //执行基类A的构造函数A(),再执行派生类的构造函数B(int) B b3 = new B(0,1); //执行执行基类A的构造函数A(int) ,再执行派生类的 |
class A { private int x; public A( int i ) { x = i; } }; class B : A { private int y; public B():A(i) { y = 0; } public B(int i):A(i) { y = i; } public B(int i, int j):A(i) { y = j; } }; |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。