Definition of a class through code:
// namespace starts from here
namespace ClassExample
{
// class starts from here
class DemoCarClass
{
string color, brand;
short year, topSpeed, engineCapacity;
public DemoCarClass()
{}
public DemoCarClass(string color ,string brand, short year, short topSpeed, short engineCapacity)
{
this.color = color;
this.brand = brand;
this.year= year;
this.topSpeed = topSpeed;
this.engineCapacity = engineCapacity;
}
public void Run()
{
// some code
}
public void RunFast(short currentSpeed)
{
if(currentSpeed <= topSpeed)
{
// some code
}
}
}
public static void Main(string[] args)
{
// object creation
DemoCarClass demoCarobject = new DemoCarClass();
}
}
Thanks and keep hardworking!!!
Ashumeet Mitter
No comments:
Post a Comment