im reading a C# book who says that if i have a derived class from a inheritable class then when i use the derived class constructor it will try to use the base class constructor with the same parameters as the derived class..i tested..but it didnt work the way the book says!PHP Code:class Class1
{
static void Main(string[] args)
{
MyDerivedClass derived = new MyDerivedClass(4);
}
}
public class MyBaseClass
{
public MyBaseClass()
{
Console.WriteLine("MyBaseClass()");
}
public MyBaseClass(int i)
{
Console.WriteLine("MyBaseClass(int i)");
}
}
public class MyDerivedClass : MyBaseClass
{
public MyDerivedClass()
{
Console.WriteLine("MyDerivedClass()");
}
public MyDerivedClass(int i)
{
Console.WriteLine("MyDerivedClass(int i)");
}
public MyDerivedClass(int i, int j)
{
Console.WriteLine("MyDerivedClass(int i,int j)");
}
}
the way i did returned:
MyBaseClass()
MyDerivedClass(int i)
when it should have returned:
MyBaseClass(int i)
MyDerivedClass(int i)
hmm...what is wrong?




Reply With Quote