C#.NET Inheritance
C#.NET Inheritance
• }
• Class Child:Base
• {
• }
Inheritance
using System;
class X {
public int a;
public X(int i)
{ a = i; }
}
class Y : X {
public int b;
public Y(int i, int j) : base(j)
{ b = i; }
}
• class BaseRef {
• static void Main() {
• X x = new X(10);
• X x2;
• Y y = new Y(5, 6);
• x2 = x; // OK, both of same type
Console.WriteLine("x2.a: " + x2.a);
• x2 = y; // OK because Y is derived from X
Console.WriteLine("x2.a: " + x2.a);
• }}