Skip to content

Instantly share code, notes, and snippets.

@hu2di
Created April 10, 2017 02:43
Show Gist options
  • Save hu2di/afe2f56e5a6dea847cb8bc928844a22a to your computer and use it in GitHub Desktop.
Save hu2di/afe2f56e5a6dea847cb8bc928844a22a to your computer and use it in GitHub Desktop.
C-sharp: Subclass doesn't inherit constructors of its parent class.
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