Default constructors are the ones that takes no parameters. Default constructors are invoked whenever an object is instantiated by using the new operator and no arguments are provided to new.
Constructors have the same name as the class, and usually initialize the data members of the new object.
class ClsTea : IRetail
{
//Variables
private string _locale;
private static string _brand;
public ClsTea()
{
_brand = "N/A";
}
}
The following snippet invokes the default constructor
ClsTea MyTea = new ClsTea();
Console.WriteLine("My default tea brand is " + ClsTea.Brand);
ClsTea.Brand = "Tata";
Console.WriteLine("My favourite tea brand is " + ClsTea.Brand);
No comments:
Post a Comment