Can abstract class have constructors?
Yes, an abstract class does have a constructor.
It will be called when it subclass is instantiated.
example:
abstract class bank
{
public bank()
{
Console.WriteLine("bank");
}
}
class icici : bank
{
icici()
{
Console.WriteLine("icici");
}
static void Main()
{
bank b = new icici();
}
}
//Output:
when the object of icici class is created,
They will be displayed in the output.
bank
icici
Yes, an abstract class does have a constructor.
It will be called when it subclass is instantiated.
example:
abstract class bank
{
public bank()
{
Console.WriteLine("bank");
}
}
class icici : bank
{
icici()
{
Console.WriteLine("icici");
}
static void Main()
{
bank b = new icici();
}
}
//Output:
when the object of icici class is created,
They will be displayed in the output.
bank
icici
No comments:
Post a Comment