Car class property

class Car
{
// member field
//string name;
//int year;
/*
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
public int Year
{
get
{
return this.year;
}
set
{
this.year = value;
}
}
*/

// property
public string Name
{
get;
set;
}
public int Year
{
get;
set;
}

 

// constructor
public Car() : this(“Avante”, 2013)
{
}

 

public Car(string name, int year)
{
this.Name = name;
this.Year = year;
}

 

// method
public void Print()
{
Console.WriteLine(“자동차 {0} 년도 {1}”, this.Name, this.Year);
}
}

 

 

 

class Program
{
static void Main(string[] args)
{
Car c1 = new Car();
c1.Print();
c1.Name = “Accent”;
c1.Print();
Console.WriteLine(c1.Name);
Car c2 = new Car(“Sonata”, 2012);
c2.Print();
}

Leave a Reply

Your email address will not be published. Required fields are marked *