using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace AutomobileClass
{
public class Automobile
{
private string type;
private string color;
private double price;
private bool isstart;
public Automobile(string type,string color,double price, bool isstart)
{
this.type = type;
this.color =color;
this.price = price;
this.isstart = isstart;
} public void Automobileinfo()
{
if(Automobile.isstart == false)
Console.WriteLine("品牌:{0},颜色:{1},价格:{2},状态:停止",type,color,price);
if(Automobile.isstart == true)
Console.WriteLine("品牌:{0},颜色:{1},价格:{2},状态: 行驶",type,color,price);
}
public void start()
{
isstart = true;
}
public void stop()
{
isstart = false;
}
class Program
{
static void Main(string[] args)
{
Automobile car1 = new Automobile("奥迪", "蓝色", 500000, false);
Automobile car2 = new Automobile("宝马", "黑色", 1000000, true);
Console.WriteLine("车辆信息如下: \n");
car1.Automobileinfo();
car2.Automobileinfo();
Console.ReadKey(); }
}
}
}
上面25行 提示非静态字段、方法或属性、、、要求对象引用 这个错误, 应该怎么解决 public void start()
{
isstart = true;
}
public void stop()
{
isstart = false;
}
还有这个在这里有什么用》?
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace AutomobileClass
{
public class Automobile
{
private string type;
private string color;
private double price;
private bool isstart;
public Automobile(string type,string color,double price, bool isstart)
{
this.type = type;
this.color =color;
this.price = price;
this.isstart = isstart;
} public void Automobileinfo()
{
if(Automobile.isstart == false)
Console.WriteLine("品牌:{0},颜色:{1},价格:{2},状态:停止",type,color,price);
if(Automobile.isstart == true)
Console.WriteLine("品牌:{0},颜色:{1},价格:{2},状态: 行驶",type,color,price);
}
public void start()
{
isstart = true;
}
public void stop()
{
isstart = false;
}
class Program
{
static void Main(string[] args)
{
Automobile car1 = new Automobile("奥迪", "蓝色", 500000, false);
Automobile car2 = new Automobile("宝马", "黑色", 1000000, true);
Console.WriteLine("车辆信息如下: \n");
car1.Automobileinfo();
car2.Automobileinfo();
Console.ReadKey(); }
}
}
}
上面25行 提示非静态字段、方法或属性、、、要求对象引用 这个错误, 应该怎么解决 public void start()
{
isstart = true;
}
public void stop()
{
isstart = false;
}
还有这个在这里有什么用》?
另外 start()和stop()这两个方法没被调用过,所以也没用