Lab1.11 Constructor
Lab1.11 Constructor
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1
{
class Car
{
public string Make;
public string Model;
public int Year;
public string Color;
// Default constructor
// This is automatically provided by C# if no constructor is defined
// Parameterless constructor
public Car()
{
Make = "Unknown";
Model = "Generic";
Year = DateTime.Now.Year;
Color = "White";
}
// Parameterized constructor
public Car(string make, string model, int year, string color)
{
Make = make;
Model = model;
Year = year;
Color = color;
}
class Program
{
static void Main(string[] args)
{
// Using default constructor
Car car1 = new Car();
Console.WriteLine("Car 1 (Default Constructor):");
car1.DisplayInfo();