1.

Can A Child Class Call The Constructor Of A Base Class?

Answer»

YES, a child class can call the constructor of a BASE class by using the base keyword as shown in the example below.

using SYSTEM;
NAMESPACE TestConsole
{
class BaseClass
{
public BaseClass(STRING str)
{
Console.WriteLine(str);
}
}
class ChildClass : BaseClass
{
public ChildClass(string str): base(str)
{
}
public static void Main()
{
ChildClass CC = new ChildClass("Calling base class constructor from child class");
}
}
}

Yes, a child class can call the constructor of a base class by using the base keyword as shown in the example below.

using System;
namespace TestConsole
{
class BaseClass
{
public BaseClass(string str)
{
Console.WriteLine(str);
}
}
class ChildClass : BaseClass
{
public ChildClass(string str): base(str)
{
}
public static void Main()
{
ChildClass CC = new ChildClass("Calling base class constructor from child class");
}
}
}



Discussion

No Comment Found