Created
April 10, 2017 02:43
-
-
Save hu2di/afe2f56e5a6dea847cb8bc928844a22a to your computer and use it in GitHub Desktop.
C-sharp: Subclass doesn't inherit constructors of its parent class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Constructor | |
{ | |
class Program | |
{ | |
class A | |
{ | |
public A () | |
{ | |
Console.WriteLine("A"); | |
} | |
} | |
class B:A | |
{ | |
public B() | |
{ | |
Console.WriteLine("B"); | |
} | |
} | |
class C : B | |
{ | |
public C () | |
{ | |
Console.WriteLine("C"); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
A x = new A(); //Result on console: A | |
A y = new B(); //Result: AB | |
A z = new C(); //Result: ABC | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment